﻿using HalconDotNet;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Drawing.Imaging;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Forms;
using XXTUserUI;

namespace MainFrame
{
    public partial class PageType : Form
    {
        public PageType()
        {
            InitializeComponent();
        }

        private void btn_deleteAMname_Click(object sender, EventArgs e)
        {
            try
            {
                //if (cbo_type_selectType.Items.Count < 1 || cbo_type_selectType.SelectedIndex < 0)
                //{
                //    displalyInfo.displayInfoMain("请先选择要删除的型号规格");
                //    return;
                //}
                //DirectoryInfo dif = new DirectoryInfo(GlobalVar.type_path);
                //foreach (var item in dif.GetFiles())
                //{
                //    if ((item.Name.Replace(".tfp", "")) == cbo_type_selectType.SelectedItem.ToString())
                //    {
                //        File.Delete(item.FullName);
                //    }
                //}
                //cbo_type_selectType.Items.RemoveAt(cbo_type_selectType.SelectedIndex);
                //cbo_type_selectType.SelectedIndex = 0;
                //GlobalVar.closeSave.CurrentTypeName = cbo_type_selectType.SelectedItem.ToString();
                //displalyInfo.displayInfoMain("所选配方已删除");
            }
            catch (System.Exception ex)
            {
                displalyInfo.displayInfoMain($"删除型号数据出错:{ex.Message}");
            }
        }
        private void saveType(string curType,string curVision)
        {
            try
            {

                if (GlobalVar.motionConfig == null)
                {
                    GlobalVar.motionConfig = new MotionConfig();
                }
                ControlToParameter();
                if (!Directory.Exists(GlobalVar.type_path))
                {
                    Directory.CreateDirectory(GlobalVar.type_path);
                }
                if (!Directory.Exists(GlobalVar.type_copy_path))
                {
                    Directory.CreateDirectory(GlobalVar.type_copy_path);
                }
                GlobalVar.closeSave.CurrentTypeName = curType + GlobalVar.char_VersionSpilt + curVision;
                SerializeHelper.serializeFile(GlobalVar.type_path + "\\" + GlobalVar.closeSave.CurrentTypeName + ".tfp", GlobalVar.motionConfig, GlobalVar.closeSave.CurrentTypeName);
                SerializeHelper.serializeFile(GlobalVar.type_copy_path + "\\" + GlobalVar.closeSave.CurrentTypeName + ".tfp", GlobalVar.motionConfig, GlobalVar.closeSave.CurrentTypeName);

            }
            catch (System.Exception ex)
            {
                displalyInfo.displayInfoMain($"型号数据保存出错:{ex.Message}");
            }
        }
        private List<AbsPostion> GetPos()
        {
            var posList = new List<AbsPostion>();
            for (int i = 0; i < posCount; i++)
            {
                posList.Add(new AbsPostion());
            }
            posList[(int)e_Pos.拍照位].X = (double)nud_pos_scanX.Value;
            posList[(int)e_Pos.拍照位].Y = (double)nud_pos_scanY.Value;
            posList[(int)e_Pos.拍照位].Z = (double)nud_pos_scanZ.Value;
            posList[(int)e_Pos.拍照位].R = (double)nud_pos_scanR.Value;

            posList[(int)e_Pos.拍照检测位].X = (double)nud_pos_ResultX.Value;
            posList[(int)e_Pos.拍照检测位].Y = (double)nud_pos_ResultY.Value;
            posList[(int)e_Pos.拍照检测位].Z = (double)nud_pos_ResultZ.Value;
            posList[(int)e_Pos.拍照检测位].R = (double)nud_pos_ResultR.Value;

            posList[(int)e_Pos.NG放标位].X = (double)nud_pos_NGX.Value;
            posList[(int)e_Pos.NG放标位].Y = (double)nud_pos_NGY.Value;
            posList[(int)e_Pos.NG放标位].Z = (double)nud_pos_NGZ.Value;
            posList[(int)e_Pos.NG放标位].ZHeight = (double)nud_pos_NGZHeight.Value;
            posList[(int)e_Pos.NG放标位].R = (double)nud_pos_NGR.Value;

            posList[(int)e_Pos.OK放标位].X = (double)nud_pos_OKX.Value;
            posList[(int)e_Pos.OK放标位].Y = (double)nud_pos_OKY.Value;
            posList[(int)e_Pos.OK放标位].Z = (double)nud_pos_OKZ.Value;
            posList[(int)e_Pos.OK放标位].ZHeight = (double)nud_pos_OKZHeight.Value;
            posList[(int)e_Pos.OK放标位].R = (double)nud_pos_OKR.Value;

            posList[(int)e_Pos.飞达取标位].X = (double)nud_GetLabelX.Value;
            posList[(int)e_Pos.飞达取标位].Y = (double)nud_GetLabelY.Value;
            posList[(int)e_Pos.飞达取标位].Z = (double)nud_GetLabelZ.Value;
            posList[(int)e_Pos.飞达取标位].ZHeight = (double)nud_GetLabelZHeight.Value;
            posList[(int)e_Pos.飞达取标位].R = (double)nud_GetLabelR.Value;

            ///////////////////////////////////////////////////////////////////////////////////////////////
            //LeftFitCompensationX.Value = (decimal)GlobalVar.userConfig.LeftFitCompensationX;
            //LeftFitCompensationY.Value = (decimal)GlobalVar.userConfig.LeftFitCompensationY;
            //LeftFitCompensationA.Value = (decimal)GlobalVar.userConfig.LeftFitCompensationA;

            posList[(int)e_Pos.视觉补偿].X = (double)LeftFitCompensationX.Value;
            posList[(int)e_Pos.视觉补偿].Y = (double)LeftFitCompensationY.Value;
            posList[(int)e_Pos.视觉补偿].R = (double)LeftFitCompensationA.Value;

            return posList;
        }
        private int posCount = 10;
        private int posNGCount = 3;
        private void SetPosList(List<AbsPostion> posList)
        {
            if (posList == null)
            {
                posList = new List<AbsPostion>();
                for (int i = 0; i < posCount; i++)
                {
                    posList.Add(new AbsPostion());
                }
            }
            if (posList[(int)e_Pos.拍照位].X < (double)nud_pos_scanX.Minimum || posList[(int)e_Pos.拍照位].X > (double)nud_pos_scanX.Maximum)
                posList[(int)e_Pos.拍照位].X = (double)nud_pos_scanX.Maximum;
            if (posList[(int)e_Pos.拍照位].Y < (double)nud_pos_scanY.Minimum || posList[(int)e_Pos.拍照位].Y > (double)nud_pos_scanY.Maximum)
                posList[(int)e_Pos.拍照位].Y = (double)nud_pos_scanY.Minimum;
            if (posList[(int)e_Pos.拍照位].Z < (double)nud_pos_scanZ.Minimum || posList[(int)e_Pos.拍照位].Z > (double)nud_pos_scanZ.Maximum)
                posList[(int)e_Pos.拍照位].Z = (double)nud_pos_scanZ.Minimum;

            nud_pos_scanX.Value = (decimal)posList[(int)e_Pos.拍照位].X;
            nud_pos_scanY.Value = (decimal)posList[(int)e_Pos.拍照位].Y;
            nud_pos_scanZ.Value = (decimal)posList[(int)e_Pos.拍照位].Z;
            nud_pos_scanR.Value = (decimal)posList[(int)e_Pos.拍照位].R;

            if (posList[(int)e_Pos.拍照检测位].Y < (double)nud_pos_ResultY.Minimum || posList[(int)e_Pos.拍照检测位].Y > (double)nud_pos_ResultY.Maximum)
                posList[(int)e_Pos.拍照检测位].Y = (double)nud_pos_ResultY.Minimum;

            nud_pos_ResultY.Value = (decimal)posList[(int)e_Pos.拍照检测位].Y;

            if (posList[(int)e_Pos.NG放标位].X < (double)nud_pos_NGX.Minimum || posList[(int)e_Pos.NG放标位].X > (double)nud_pos_NGX.Maximum)
                posList[(int)e_Pos.NG放标位].X = (double)nud_pos_NGX.Maximum;
            if (posList[(int)e_Pos.NG放标位].Y < (double)nud_pos_NGY.Minimum || posList[(int)e_Pos.NG放标位].Y > (double)nud_pos_NGY.Maximum)
                posList[(int)e_Pos.NG放标位].Y = (double)nud_pos_NGY.Minimum;
            if (posList[(int)e_Pos.NG放标位].Z < (double)nud_pos_NGZ.Minimum || posList[(int)e_Pos.NG放标位].Z > (double)nud_pos_NGZ.Maximum)
                posList[(int)e_Pos.NG放标位].Z = (double)nud_pos_NGZ.Minimum;
            if (posList[(int)e_Pos.NG放标位].ZHeight < (double)nud_pos_NGZHeight.Minimum || posList[(int)e_Pos.NG放标位].ZHeight > (double)nud_pos_NGZHeight.Maximum)
                posList[(int)e_Pos.NG放标位].ZHeight = (double)nud_pos_NGZHeight.Minimum;
            if (posList[(int)e_Pos.NG放标位].R < (double)nud_pos_NGR.Minimum || posList[(int)e_Pos.NG放标位].R > (double)nud_pos_NGR.Maximum)
                posList[(int)e_Pos.NG放标位].R = (double)nud_pos_NGR.Minimum;
            nud_pos_NGX.Value = (decimal)posList[(int)e_Pos.NG放标位].X;
            nud_pos_NGY.Value = (decimal)posList[(int)e_Pos.NG放标位].Y;
            nud_pos_NGZ.Value = (decimal)posList[(int)e_Pos.NG放标位].Z;
            nud_pos_NGZHeight.Value = (decimal)posList[(int)e_Pos.NG放标位].ZHeight;
            nud_pos_NGR.Value = (decimal)posList[(int)e_Pos.NG放标位].R;

            if (posList[(int)e_Pos.OK放标位].X < (double)nud_pos_OKX.Minimum || posList[(int)e_Pos.OK放标位].X > (double)nud_pos_OKX.Maximum)
                posList[(int)e_Pos.OK放标位].X = (double)nud_pos_OKX.Maximum;
            if (posList[(int)e_Pos.OK放标位].Y < (double)nud_pos_OKY.Minimum || posList[(int)e_Pos.OK放标位].Y > (double)nud_pos_OKY.Maximum)
                posList[(int)e_Pos.OK放标位].Y = (double)nud_pos_OKY.Minimum;
            if (posList[(int)e_Pos.OK放标位].Z < (double)nud_pos_OKZ.Minimum || posList[(int)e_Pos.OK放标位].Z > (double)nud_pos_OKZ.Maximum)
                posList[(int)e_Pos.OK放标位].Z = (double)nud_pos_OKZ.Minimum;
            if (posList[(int)e_Pos.OK放标位].ZHeight < (double)nud_pos_OKZHeight.Minimum || posList[(int)e_Pos.OK放标位].ZHeight > (double)nud_pos_OKZHeight.Maximum)
                posList[(int)e_Pos.OK放标位].ZHeight = (double)nud_pos_OKZHeight.Minimum;
            if (posList[(int)e_Pos.OK放标位].R < (double)nud_pos_OKR.Minimum || posList[(int)e_Pos.OK放标位].R > (double)nud_pos_OKR.Maximum)
                posList[(int)e_Pos.OK放标位].R = (double)nud_pos_OKR.Minimum;
            nud_pos_OKX.Value = (decimal)posList[(int)e_Pos.OK放标位].X;
            nud_pos_OKY.Value = (decimal)posList[(int)e_Pos.OK放标位].Y;
            nud_pos_OKZ.Value = (decimal)posList[(int)e_Pos.OK放标位].Z;
            nud_pos_OKZHeight.Value = (decimal)posList[(int)e_Pos.OK放标位].ZHeight;
            nud_pos_OKR.Value = (decimal)posList[(int)e_Pos.OK放标位].R;


            if (posList[(int)e_Pos.飞达取标位].X < (double)nud_GetLabelX.Minimum || posList[(int)e_Pos.飞达取标位].X > (double)nud_GetLabelX.Maximum)
                posList[(int)e_Pos.飞达取标位].X = (double)nud_GetLabelX.Maximum;
            if (posList[(int)e_Pos.飞达取标位].Y < (double)nud_GetLabelY.Minimum || posList[(int)e_Pos.飞达取标位].Y > (double)nud_GetLabelY.Maximum)
                posList[(int)e_Pos.飞达取标位].Y = (double)nud_GetLabelY.Minimum;
            if (posList[(int)e_Pos.飞达取标位].Z < (double)nud_GetLabelZ.Minimum || posList[(int)e_Pos.飞达取标位].Z > (double)nud_GetLabelZ.Maximum)
                posList[(int)e_Pos.飞达取标位].Z = (double)nud_GetLabelZ.Minimum;
            if (posList[(int)e_Pos.飞达取标位].ZHeight < (double)nud_GetLabelZHeight.Minimum || posList[(int)e_Pos.飞达取标位].ZHeight > (double)nud_GetLabelZHeight.Maximum)
                posList[(int)e_Pos.飞达取标位].ZHeight = (double)nud_GetLabelZHeight.Minimum;
            if (posList[(int)e_Pos.飞达取标位].R < (double)nud_GetLabelR.Minimum || posList[(int)e_Pos.飞达取标位].R > (double)nud_GetLabelR.Maximum)
                posList[(int)e_Pos.飞达取标位].R = (double)nud_GetLabelR.Minimum;

            nud_GetLabelX.Value = (decimal)posList[(int)e_Pos.飞达取标位].X;
            nud_GetLabelY.Value = (decimal)posList[(int)e_Pos.飞达取标位].Y;
            nud_GetLabelZ.Value = (decimal)posList[(int)e_Pos.飞达取标位].Z;
            nud_GetLabelZHeight.Value = (decimal)posList[(int)e_Pos.飞达取标位].ZHeight;
            nud_GetLabelR.Value = (decimal)posList[(int)e_Pos.飞达取标位].R;


            if (posList[(int)e_Pos.视觉补偿].X < (double)LeftFitCompensationX.Minimum || posList[(int)e_Pos.视觉补偿].X > (double)LeftFitCompensationX.Maximum)
                posList[(int)e_Pos.视觉补偿].X = (double)0;
            if (posList[(int)e_Pos.视觉补偿].Y < (double)LeftFitCompensationY.Minimum || posList[(int)e_Pos.视觉补偿].Y > (double)LeftFitCompensationY.Maximum)
                posList[(int)e_Pos.视觉补偿].Y = (double)0;
            if (posList[(int)e_Pos.视觉补偿].R < (double)LeftFitCompensationA.Minimum || posList[(int)e_Pos.视觉补偿].R > (double)LeftFitCompensationA.Maximum)
                posList[(int)e_Pos.视觉补偿].R = (double)0;

            LeftFitCompensationX.Value = (decimal)posList[(int)e_Pos.视觉补偿].X;
            LeftFitCompensationY.Value = (decimal)posList[(int)e_Pos.视觉补偿].Y;
            LeftFitCompensationA.Value = (decimal)posList[(int)e_Pos.视觉补偿].R;


        }
        //private e_CameraPlate GetDrawSelect_T()
        //{
        //    var res = e_CameraPlate.图案相机平台1;
        //    if(rbn_v_plate1.Checked)
        //        res = e_CameraPlate.图案相机平台1;
        //    else if (rbn_v_plate2.Checked)
        //        res = e_CameraPlate.图案相机平台2;
        //    return res;
        //}
        private void SetCutLimit()
        {

            var cutX_min = -264;
            var cutX_max = 0;
            nud_cut_WaitX.Minimum = cutX_min;
            nud_cut_WaitX.Maximum = cutX_max;

            nud_cut_ClampX.Minimum = cutX_min;
            nud_cut_ClampX.Maximum = cutX_max;

            nud_cut_mediumX.Minimum = cutX_min;
            nud_cut_mediumX.Maximum = cutX_max;

            nud_cut_EndX.Minimum = cutX_min;
            nud_cut_EndX.Maximum = cutX_max;


            nud_cut_NGX.Minimum = cutX_min;
            nud_cut_NGX.Maximum = cutX_max;

            nud_cut_ProX.Minimum = cutX_min;
            nud_cut_ProX.Maximum = cutX_max;

            var cutY_min = 0;
            var cutY_max = 299;
            nud_cut_WaitY.Minimum = cutY_min;
            nud_cut_WaitY.Maximum = cutY_max;

            nud_cut_ClampY.Minimum = cutY_min;
            nud_cut_ClampY.Maximum = cutY_max;

            nud_cut_mediumY.Minimum = cutY_min;
            nud_cut_mediumY.Maximum = cutY_max;

            nud_cut_EndY.Minimum = cutY_min;
            nud_cut_EndY.Maximum = cutY_max;


            nud_cut_NGY.Minimum = cutY_min;
            nud_cut_NGY.Maximum = cutY_max;

            nud_cut_ProY.Minimum = cutY_min;
            nud_cut_ProY.Maximum = cutY_max;

            var cutZ_min = 0;
            var cutZ_max = 85;
            nud_cut_WaitZ.Minimum = cutZ_min;
            nud_cut_WaitZ.Maximum = cutZ_max;

            nud_cut_ClampZ.Minimum = cutZ_min;
            nud_cut_ClampZ.Maximum = cutZ_max;

            nud_cut_mediumZ.Minimum = cutZ_min;
            nud_cut_mediumZ.Maximum = cutZ_max;

            nud_cut_EndZ.Minimum = cutZ_min;
            nud_cut_EndZ.Maximum = cutZ_max;


            nud_cut_NGZ.Minimum = cutZ_min;
            nud_cut_NGZ.Maximum = cutZ_max;

            nud_cut_ProZ.Minimum = cutZ_min;
            nud_cut_ProZ.Maximum = cutZ_max;

            var cutR1_min = 0;
            var cutR1_max = 359;
            nud_cut_WaitR1.Minimum = cutR1_min;
            nud_cut_WaitR1.Maximum = cutR1_max;

            nud_cut_ClampR1.Minimum = cutR1_min;
            nud_cut_ClampR1.Maximum = cutR1_max;

            nud_cut_mediumR1.Minimum = cutR1_min;
            nud_cut_mediumR1.Maximum = cutR1_max;

            nud_cut_EndR1.Minimum = cutR1_min;
            nud_cut_EndR1.Maximum = cutR1_max;


            nud_cut_NGR1.Minimum = cutR1_min;
            nud_cut_NGR1.Maximum = cutR1_max;

            nud_cut_ProR1.Minimum = cutR1_min;
            nud_cut_ProR1.Maximum = cutR1_max;

            var cutR2_min = 0;
            var cutR2_max = 359;
            nud_cut_WaitR2.Minimum = cutR2_min;
            nud_cut_WaitR2.Maximum = cutR2_max;

            nud_cut_ClampR2.Minimum = cutR2_min;
            nud_cut_ClampR2.Maximum = cutR2_max;

            nud_cut_mediumR2.Minimum = cutR2_min;
            nud_cut_mediumR2.Maximum = cutR2_max;

            nud_cut_EndR2.Minimum = cutR2_min;
            nud_cut_EndR2.Maximum = cutR2_max;


            nud_cut_NGR2.Minimum = cutR2_min;
            nud_cut_NGR2.Maximum = cutR2_max;

            nud_cut_ProR2.Minimum = cutR2_min;
            nud_cut_ProR2.Maximum = cutR2_max;


            nud_downProZ.Minimum = -65;
            nud_downProZ.Maximum = 0;
            nud_upProZ.Minimum = -65;
            nud_upProZ.Maximum = 0;

        }
        private void SetLabelLimit(int nPlate)
        {


            //var GetLabelXmax = 0;
            //var GetLabelXmin = -100;
            //var GetLabelYmax = 50;
            //var GetLabelYmin = 0;
            //var GetLabelRmax = 4;
            //var GetLabelRmin = -30;
            //var GetLabelZmax = 40;
            //var GetLabelZmin =0;

            //var Pos_ScanXmax = -100;
            Limit.Pos_ScanXmin = -205;
            //var Pos_ScanYmax = 300;
            //var Pos_ScanYmin = 100;
            //var Pos_ScanZmax = 10;
            //var Pos_ScanZmin = 0;

            //var PosNGX_Max= 0;
            //var PosNGX_Min = -50;
            //var PosNGY_Max = 300;
            //var PosNGY_Min =100;
            //var PosNGZ_Max =130;
            //var PosNGZ_Min = 0;
            //var PosNGZHeight_Max =30;
            //var PosNGZHeight_Min = 0;
            //var PosNGR_Max = 0;
            //var PosNGR_Min = -100;

            //var PosOKX_Max = 0;
            Limit.PosOKX_Min = -210;
            //var PosOKY_Max = 550;
            //var PosOKY_Min = 500;
            //var PosOKZ_Max = 230;
            //var PosOKZ_Min = 100;
            //var PosOKZHeight_Max =100;
            //var PosOKZHeight_Min = 0;
            //var PosOKR_Max = 0;
            //var PosOKR_Min = -100;
            try
            {
                if (nPlate == (int)e_platePro.平台2)
                {
                    Limit.Pos_ScanXmin = -230;
                    Limit.PosOKX_Min = -230;
                }
                //nud_GetLabelX.Maximum = GetLabelXmax;
                //nud_GetLabelX.Minimum = GetLabelXmin;
                //nud_GetLabelY.Maximum = GetLabelYmax;
                //nud_GetLabelY.Minimum = GetLabelYmin;
                //nud_GetLabelR.Maximum = GetLabelRmax;
                //nud_GetLabelR.Minimum = GetLabelRmin;
                //nud_GetLabelZ.Maximum = GetLabelZmax;
                //nud_GetLabelZ.Minimum = GetLabelZmin;
                //nud_GetLabelZHeight.Maximum = GetLabelZmax;
                //nud_GetLabelZHeight.Minimum = GetLabelZmin;

                //nud_pos_scanX.Maximum = Pos_ScanXmax;
                //nud_pos_scanX.Minimum = Pos_ScanXmin;
                //nud_pos_scanY.Maximum = Pos_ScanYmax;
                //nud_pos_scanY.Minimum = Pos_ScanYmin;
                //nud_pos_scanZ.Maximum = Pos_ScanZmax;
                //nud_pos_scanZ.Minimum = Pos_ScanZmin;

                //nud_pos_NGY.Maximum = PosNGY_Max;
                //nud_pos_NGY.Minimum = PosNGY_Min;
                //nud_pos_NGX.Maximum = PosNGX_Max;
                //nud_pos_NGX.Minimum = PosNGX_Min;
                //nud_pos_NGZ.Maximum = PosNGZ_Max;
                //nud_pos_NGZ.Minimum = PosNGZ_Min;
                //nud_pos_NGR.Maximum = PosNGR_Max;
                //nud_pos_NGR.Minimum = PosNGR_Min;
                //nud_pos_NGZHeight.Maximum = PosNGZHeight_Max;
                //nud_pos_NGZHeight.Minimum = PosNGZHeight_Min;

                //nud_pos_OKY.Maximum = PosOKY_Max;
                //nud_pos_OKY.Minimum = PosOKY_Min;
                //nud_pos_OKX.Maximum = PosOKX_Max;
                //nud_pos_OKX.Minimum = PosOKX_Min;
                //nud_pos_OKZ.Maximum = PosOKZ_Max;
                //nud_pos_OKZ.Minimum = PosOKZ_Min;
                //nud_pos_OKR.Maximum = PosOKR_Max;
                //nud_pos_OKR.Minimum = PosOKR_Min;
                //nud_pos_OKZHeight.Maximum = PosOKZHeight_Max;
                //nud_pos_OKZHeight.Minimum = PosOKZHeight_Min;
                nud_GetLabelX.Maximum = Limit.GetLabelXmax;
                nud_GetLabelX.Minimum = Limit.GetLabelXmin;
                nud_GetLabelY.Maximum = Limit.GetLabelYmax;
                nud_GetLabelY.Minimum = Limit.GetLabelYmin;
                if (nPlate == (int)e_platePro.平台2)
                {
                    nud_GetLabelR.Maximum = 180;
                    nud_GetLabelR.Minimum =0;
                }
                else
                {
                    nud_GetLabelR.Maximum = Limit.GetLabelRmax;
                    nud_GetLabelR.Minimum = Limit.GetLabelRmin;
                }

                nud_GetLabelZ.Maximum = Limit.GetLabelZmax;
                nud_GetLabelZ.Minimum = Limit.GetLabelZmin;
                nud_GetLabelZHeight.Maximum = Limit.GetLabelZmax;
                nud_GetLabelZHeight.Minimum = Limit.GetLabelZmin;

                nud_pos_scanX.Maximum = Limit.Pos_ScanXmax;
                nud_pos_scanX.Minimum = Limit.Pos_ScanXmin;
                nud_pos_scanY.Maximum = Limit.Pos_ScanYmax;
                nud_pos_scanY.Minimum = Limit.Pos_ScanYmin;
                nud_pos_scanZ.Maximum = Limit.Pos_ScanZmax;
                nud_pos_scanZ.Minimum = Limit.Pos_ScanZmin;

                nud_pos_NGY.Maximum = Limit.PosNGY_Max;
                nud_pos_NGY.Minimum = Limit.PosNGY_Min;
                nud_pos_NGX.Maximum = Limit.PosNGX_Max;
                nud_pos_NGX.Minimum = Limit.PosNGX_Min;
                nud_pos_NGZ.Maximum = Limit.PosNGZ_Max;
                nud_pos_NGZ.Minimum = Limit.PosNGZ_Min;
                if (nPlate == (int)e_platePro.平台2)
                {
                    nud_pos_NGR.Maximum = 100;
                    nud_pos_NGR.Minimum = 0;
                }
                else
                {
                    nud_pos_NGR.Maximum = Limit.PosNGR_Max;
                    nud_pos_NGR.Minimum = Limit.PosNGR_Min;
                }

                nud_pos_NGZHeight.Maximum = Limit.PosNGZHeight_Max;
                nud_pos_NGZHeight.Minimum = Limit.PosNGZHeight_Min;

                nud_pos_OKY.Maximum = Limit.PosOKY_Max;
                nud_pos_OKY.Minimum = Limit.PosOKY_Min;
                nud_pos_OKX.Maximum = Limit.PosOKX_Max;
                nud_pos_OKX.Minimum = Limit.PosOKX_Min;
                nud_pos_OKZ.Maximum = Limit.PosOKZ_Max;
                nud_pos_OKZ.Minimum = Limit.PosOKZ_Min;
                if (nPlate == (int)e_platePro.平台2)
                {
                    nud_pos_OKR.Maximum = 210;
                    nud_pos_OKR.Minimum = 0;
                }
                else
                {
                    nud_pos_OKR.Maximum = Limit.PosOKR_Max;
                    nud_pos_OKR.Minimum = Limit.PosOKR_Min;
                }

                nud_pos_OKZHeight.Maximum = Limit.PosOKZHeight_Max;
                nud_pos_OKZHeight.Minimum = Limit.PosOKZHeight_Min;

                LeftFitCompensationX.Maximum = 100;
                LeftFitCompensationX.Minimum = -100;

                LeftFitCompensationY.Maximum = 100;
                LeftFitCompensationY.Minimum = -100;

                LeftFitCompensationA.Maximum = 100;
                LeftFitCompensationA.Minimum = -100;

            }
            catch (Exception ex)
            {
                displalyInfo.displayErrorMain(ex.Message);
            }

        }

        private void UpdataCutPos()
        {
            nud_cut_WaitX.Value = (decimal)GlobalVar.motionConfig.Cut_pos[(int)e_PosCut.撕膜等料位].X;
            nud_cut_WaitY.Value = (decimal)GlobalVar.motionConfig.Cut_pos[(int)e_PosCut.撕膜等料位].Y;
            nud_cut_WaitZ.Value = (decimal)GlobalVar.motionConfig.Cut_pos[(int)e_PosCut.撕膜等料位].Z;
            nud_cut_WaitR1.Value = (decimal)GlobalVar.motionConfig.Cut_pos[(int)e_PosCut.撕膜等料位].R1;
            nud_cut_WaitR2.Value = (decimal)GlobalVar.motionConfig.Cut_pos[(int)e_PosCut.撕膜等料位].R2;

            nud_cut_ProX.Value = (decimal)GlobalVar.motionConfig.Cut_pos[(int)e_PosCut.撕膜水平位].X;
            nud_cut_ProY.Value = (decimal)GlobalVar.motionConfig.Cut_pos[(int)e_PosCut.撕膜水平位].Y;
            nud_cut_ProZ.Value = (decimal)GlobalVar.motionConfig.Cut_pos[(int)e_PosCut.撕膜水平位].Z;
            nud_cut_ProR1.Value = (decimal)GlobalVar.motionConfig.Cut_pos[(int)e_PosCut.撕膜水平位].R1;
            nud_cut_ProR2.Value = (decimal)GlobalVar.motionConfig.Cut_pos[(int)e_PosCut.撕膜水平位].R2;

            nud_cut_ClampX.Value = (decimal)GlobalVar.motionConfig.Cut_pos[(int)e_PosCut.夹膜位].X;
            nud_cut_ClampY.Value = (decimal)GlobalVar.motionConfig.Cut_pos[(int)e_PosCut.夹膜位].Y;
            nud_cut_ClampZ.Value = (decimal)GlobalVar.motionConfig.Cut_pos[(int)e_PosCut.夹膜位].Z;
            nud_cut_ClampR1.Value = (decimal)GlobalVar.motionConfig.Cut_pos[(int)e_PosCut.夹膜位].R1;
            nud_cut_ClampR2.Value = (decimal)GlobalVar.motionConfig.Cut_pos[(int)e_PosCut.夹膜位].R2;

            nud_cut_EndX.Value = (decimal)GlobalVar.motionConfig.Cut_pos[(int)e_PosCut.撕膜终点位].X;
            nud_cut_EndY.Value = (decimal)GlobalVar.motionConfig.Cut_pos[(int)e_PosCut.撕膜终点位].Y;
            nud_cut_EndZ.Value = (decimal)GlobalVar.motionConfig.Cut_pos[(int)e_PosCut.撕膜终点位].Z;
            nud_cut_EndR1.Value = (decimal)GlobalVar.motionConfig.Cut_pos[(int)e_PosCut.撕膜终点位].R1;
            nud_cut_EndR2.Value = (decimal)GlobalVar.motionConfig.Cut_pos[(int)e_PosCut.撕膜终点位].R2;

            nud_cut_mediumX.Value = (decimal)GlobalVar.motionConfig.Cut_pos[(int)e_PosCut.撕膜过度位].X;
            nud_cut_mediumY.Value = (decimal)GlobalVar.motionConfig.Cut_pos[(int)e_PosCut.撕膜过度位].Y;
            nud_cut_mediumZ.Value = (decimal)GlobalVar.motionConfig.Cut_pos[(int)e_PosCut.撕膜过度位].Z;
            nud_cut_mediumR1.Value = (decimal)GlobalVar.motionConfig.Cut_pos[(int)e_PosCut.撕膜过度位].R1;
            nud_cut_mediumR2.Value = (decimal)GlobalVar.motionConfig.Cut_pos[(int)e_PosCut.撕膜过度位].R2;

            nud_cut_NGX.Value = (decimal)GlobalVar.motionConfig.Cut_pos[(int)e_PosCut.撕膜垃圾位].X;
            nud_cut_NGY.Value = (decimal)GlobalVar.motionConfig.Cut_pos[(int)e_PosCut.撕膜垃圾位].Y;
            nud_cut_NGZ.Value = (decimal)GlobalVar.motionConfig.Cut_pos[(int)e_PosCut.撕膜垃圾位].Z;
            nud_cut_NGR1.Value = (decimal)GlobalVar.motionConfig.Cut_pos[(int)e_PosCut.撕膜垃圾位].R1;
            nud_cut_NGR2.Value = (decimal)GlobalVar.motionConfig.Cut_pos[(int)e_PosCut.撕膜垃圾位].R2;

            nud_cut_SafeX.Value = (decimal)GlobalVar.motionConfig.Cut_pos[(int)e_PosCut.撕膜安全位].X;
            nud_cut_SafeY.Value = (decimal)GlobalVar.motionConfig.Cut_pos[(int)e_PosCut.撕膜安全位].Y;
            nud_cut_SafeZ.Value = (decimal)GlobalVar.motionConfig.Cut_pos[(int)e_PosCut.撕膜安全位].Z;
            nud_cut_SafeR1.Value = (decimal)GlobalVar.motionConfig.Cut_pos[(int)e_PosCut.撕膜安全位].R1;
            nud_cut_SafeR2.Value = (decimal)GlobalVar.motionConfig.Cut_pos[(int)e_PosCut.撕膜安全位].R2;
        }

        private void ParameterToControl(string typeVersion)
        {
            try
            {
                if (GlobalVar.motionConfig == null)
                {
                    GlobalVar.motionConfig = new MotionConfig();
                }
                
                #region 撕膜
                if (GlobalVar.motionConfig.Cut_pos == null)
                {
                    GlobalVar.motionConfig.Cut_pos = new List<CutPostion>();
                    var posCutCount = Enum.GetNames(typeof(e_PosCut)).Length;
                    for (int p = 0; p < posCutCount; p++)
                    {
                        GlobalVar.motionConfig.Cut_pos.Add(new CutPostion());
                    }
                }
                UpdataCutPos();

                nud_upProZ.Value = (decimal)GlobalVar.motionConfig.ProZ_up;
                nud_downProZ.Value = (decimal)GlobalVar.motionConfig.ProZ_down;

                nud_clamp_delay.Value = (decimal)GlobalVar.motionConfig.clamp_Delay;

                nud_cut_NGZHeight.Value = (decimal)GlobalVar.motionConfig.CutNG_HeightZ;
                nud_cut_NGZLow.Value = (decimal)GlobalVar.motionConfig.CutNG_LowZ;
                nud_cut_NGZTime.Value = (decimal)GlobalVar.motionConfig.CutNG_time;
                nud_cut_NGZDelay.Value = (decimal)GlobalVar.motionConfig.CutNG_Delay;

                nud_airCutTime.Value = (decimal)GlobalVar.motionConfig.airCutTime;
         
                #endregion
                #region 吸放标
                if (rbn_plate1.Checked)
                {
                    SetLabelLimit((int)e_platePro.平台1);
                    SetPosList(GlobalVar.motionConfig.Plate1_pos);

                }
                else
                {
                    SetLabelLimit((int)e_platePro.平台2);
                    SetPosList(GlobalVar.motionConfig.Plate2_pos);

                }
                if (GlobalVar.motionConfig.LaserNG_pos == null)
                {
                    GlobalVar.motionConfig.LaserNG_pos = new List<NGPostion>();
                    for (int p = 0; p < posNGCount; p++)
                    {
                        GlobalVar.motionConfig.LaserNG_pos.Add(new NGPostion());
                    }
                }
                nud_NGGetY.Value = (decimal)GlobalVar.motionConfig.LaserNG_pos[(int)e_PosNG.NG取工装位].Y;
                nud_NGGetZup.Value = (decimal)GlobalVar.motionConfig.LaserNG_pos[(int)e_PosNG.NG取工装位].Zup;
                nud_NGGetZdown.Value = (decimal)GlobalVar.motionConfig.LaserNG_pos[(int)e_PosNG.NG取工装位].Zdown;
                nud_NGPutY.Value = (decimal)GlobalVar.motionConfig.LaserNG_pos[(int)e_PosNG.NG放工装位].Y;
                nud_NGPutZup.Value = (decimal)GlobalVar.motionConfig.LaserNG_pos[(int)e_PosNG.NG放工装位].Zup;
                nud_NGPutZdown.Value = (decimal)GlobalVar.motionConfig.LaserNG_pos[(int)e_PosNG.NG放工装位].Zdown;
           
                nud_scanSafeX1.Value = (decimal)GlobalVar.motionConfig.scanSafeX1;
                nud_scanSafeX2.Value = (decimal)GlobalVar.motionConfig.scanSafeX2;

                nud_NGLabelZ.Value = (decimal)GlobalVar.motionConfig.NGlabelZ;
                if (GlobalVar.motionConfig.checkPosY < (double)nud_checkPosY.Minimum || GlobalVar.motionConfig.checkPosY > (double)nud_checkPosY.Maximum)
                {
                    GlobalVar.motionConfig.checkPosY = (double)nud_checkPosY.Minimum;
                }
                nud_checkPosY.Value = (decimal)GlobalVar.motionConfig.checkPosY;

                //20241212增加
                if (GlobalVar.motionConfig.Up_checkPosY < (double)nud_UpcheckPosY.Minimum || GlobalVar.motionConfig.Up_checkPosY > (double)nud_UpcheckPosY.Maximum)
                {
                    GlobalVar.motionConfig.Up_checkPosY = (double)nud_UpcheckPosY.Minimum;
                }
                nud_UpcheckPosY.Value = (decimal)GlobalVar.motionConfig.Up_checkPosY;

                if (GlobalVar.motionConfig.Down_checkPosY < (double)nud_DowncheckPosY.Minimum || GlobalVar.motionConfig.Down_checkPosY > (double)nud_DowncheckPosY.Maximum)
                {
                    GlobalVar.motionConfig.Down_checkPosY = (double)nud_DowncheckPosY.Minimum;
                }
                nud_DowncheckPosY.Value = (decimal)GlobalVar.motionConfig.Down_checkPosY;


                #endregion
                #region 飞达
                nud_delayStopFly1.Value = GlobalVar.motionConfig.delayFlyStop1;
                nud_delayStopFly2.Value = GlobalVar.motionConfig.delayFlyStop2;
                nud_Fly1TimeOutAlarm.Value = GlobalVar.motionConfig.Fly1TimeOutAlarm;
                nud_Fly2TimeOutAlarm.Value = GlobalVar.motionConfig.Fly2TimeOutAlarm;
                nud_flyStop1.Value = GlobalVar.motionConfig.FlyStop1;
                nud_flyStop2.Value = GlobalVar.motionConfig.FlyStop2;


                nud_flyAlarmCount1.Value = GlobalVar.motionConfig.fly1_AlarmCount;
                nud_flyAlarmCount2.Value = GlobalVar.motionConfig.fly2_AlarmCount;
                nud_flyCount1.Value = GlobalVar.motionConfig.fly1_Count;
                nud_flyCount2.Value = GlobalVar.motionConfig.fly2_Count;

                nud_flydelayCheck.Value = GlobalVar.motionConfig.flydelayCheck;


                nud_flyAngleEnd1.Value = (decimal)GlobalVar.motionConfig.fly1AngelEnd;
                nud_flyAngleStart1.Value = (decimal)GlobalVar.motionConfig.fly1AngelStart;
                nud_flyAngleUnit1.Value = (decimal)GlobalVar.motionConfig.fly1AngelUnit;
                nud_flyAngleEnd2.Value = (decimal)GlobalVar.motionConfig.fly2AngelEnd;
                nud_flyAngleStart2.Value = (decimal)GlobalVar.motionConfig.fly2AngelStart;
                nud_flyAngleUnit2.Value = (decimal)GlobalVar.motionConfig.fly2AngelUnit;

                nud_fly1Updelay.Value = GlobalVar.motionConfig.fly1Updeley;
                nud_fly2Updelay.Value = GlobalVar.motionConfig.fly2Updeley;

                textBox3.Text = GlobalVar.motionConfig.VisionPath;
                #endregion


                #region 图像处理
                //if (GlobalVar.motionConfig.visionBase1 == null)
                //    GlobalVar.motionConfig.visionBase1 = new VisionPos();
                //if (GlobalVar.motionConfig.visionBase2 == null)
                //    GlobalVar.motionConfig.visionBase2 = new VisionPos();
                #region 定位相机
                //var curSelect = GetDrawSelect_T();
                //if (GlobalVar.motionConfig.TC_list == null)
                //    GlobalVar.motionConfig.TC_list = new List<TemplateParam>();
                //var tcount1 = Enum.GetNames(typeof(e_CameraPlate)).Length;
                //for (int i = 0; i < tcount1; i++)
                //{
                //    GlobalVar.motionConfig.TC_list.Add(new TemplateParam());
                //}
                //if (GlobalVar.motionConfig.TF_list == null)
                //    GlobalVar.motionConfig.TF_list = new List<TemplateFindParam>();
                //var tcount2 = Enum.GetNames(typeof(e_CameraPlate)).Length;
                //for (int i = 0; i < tcount2; i++)
                //{
                //    GlobalVar.motionConfig.TF_list.Add(new TemplateFindParam());
                //}
                //set_TemplateFind(GlobalVar.motionConfig.TF_list[(int)curSelect]);
                //set_TemplateCreate(GlobalVar.motionConfig.TC_list[(int)curSelect]);
            
                #endregion
                #region 定位直线


                //if (GlobalVar.motionConfig.PosLindFind1 == null)
                //{
                //    GlobalVar.motionConfig.PosLindFind1 = new List<LindFindParam>();
                //}
                //if (GlobalVar.motionConfig.PosLindFind2 == null)
                //{
                //    GlobalVar.motionConfig.PosLindFind2 = new List<LindFindParam>();
                //}
                //var LCount = (int)e_Region.直线区域2 - (int)e_Region.直线区域1 + 1;
                //for (int i = GlobalVar.motionConfig.PosLindFind1.Count; i < LCount; i++)
                //{
                //    GlobalVar.motionConfig.PosLindFind1.Add(new LindFindParam());
                //}
                //for (int i = GlobalVar.motionConfig.PosLindFind2.Count; i < LCount; i++)
                //{
                //    GlobalVar.motionConfig.PosLindFind2.Add(new LindFindParam());
                //}

              
                #endregion
                #region 定位圆
                //if (GlobalVar.motionConfig.PosCircleFindCheck1 == null)
                //{
                //    GlobalVar.motionConfig.PosCircleFindCheck1 = new List<CircleFindParam>();
                //}
                //if (GlobalVar.motionConfig.PosCircleFindCheck2 == null)
                //{
                //    GlobalVar.motionConfig.PosCircleFindCheck2 = new List<CircleFindParam>();
                //}
                //var cCount = 1;
                //for (int i = GlobalVar.motionConfig.PosCircleFindCheck1.Count; i < cCount; i++)
                //{
                //    GlobalVar.motionConfig.PosCircleFindCheck1.Add(new CircleFindParam());
                //}
                //for (int i = GlobalVar.motionConfig.PosCircleFindCheck2.Count; i < LCount; i++)
                //{
                //    GlobalVar.motionConfig.PosCircleFindCheck2.Add(new CircleFindParam());
                //}

           
                #endregion
                #region  图案
                //if (curSelect == e_CameraPlate.图案相机平台1)
                //{
                //    SetDrawInfo(GlobalVar.motionConfig.draw1);
                //}
                //else if (curSelect == e_CameraPlate.图案相机平台2)
                //{
                //    SetDrawInfo(GlobalVar.motionConfig.draw2);
                //}
                //rbt_dir_NGDraw.Text = GlobalVar.motionConfig.dir_ScanNG;
                //rbt_dir_OKDraw.Text = GlobalVar.motionConfig.dir_ScanOK;
                #endregion
                #region 检测
                //var mcount = cbx_c_RegionSelect.Items.Count;
                //if (GlobalVar.motionConfig.vision_M1_list == null)
                //    GlobalVar.motionConfig.vision_M1_list = new List<MeasureParma>();
                //for (int i = GlobalVar.motionConfig.vision_M1_list.Count; i < mcount; i++)
                //{
                //    GlobalVar.motionConfig.vision_M1_list.Add(new MeasureParma());
                //}
                //if (GlobalVar.motionConfig.vision_M2_list == null)
                //    GlobalVar.motionConfig.vision_M2_list = new List<MeasureParma>();
                //for (int i = GlobalVar.motionConfig.vision_M2_list.Count; i < mcount; i++)
                //{
                //    GlobalVar.motionConfig.vision_M2_list.Add(new MeasureParma());
                //}
                //if (rbn_m_Plate1.Checked)
                //{
                //    #region 直线检测
                //    if (cbx_c_RegionSelect.SelectedIndex > -1)
                //    {
                //        Set_Measure(GlobalVar.motionConfig.vision_M1_list[cbx_c_RegionSelect.SelectedIndex]);
                //    }
                //    if (GlobalVar.motionConfig.cutParma1 == null)
                //        GlobalVar.motionConfig.cutParma1 = new CutParma();
                //    Set_Cut(GlobalVar.motionConfig.cutParma1);

                //    var l_arr = Enum.GetNames(typeof(e_Line));
                //    #endregion
                //    #region 圆检测
                //    if (GlobalVar.motionConfig.CircleFindCheck1 == null)
                //        GlobalVar.motionConfig.CircleFindCheck1 = new List<CircleFindParam>();
                //    var c_arr = Enum.GetNames(typeof(e_Circle));
                //    for (int n = GlobalVar.motionConfig.CircleFindCheck1.Count; n < c_arr.Length; n++)
                //    {
                //        GlobalVar.motionConfig.CircleFindCheck1.Add(new CircleFindParam());
                //    }
                //    Set_CircleParam(GlobalVar.motionConfig.CircleFindCheck1[0]);
                //    #endregion
                //}
                //else
                //{
                //    #region 直线检测
                //    if (cbx_c_RegionSelect.SelectedIndex > -1)
                //    {
                //        Set_Measure(GlobalVar.motionConfig.vision_M2_list[cbx_c_RegionSelect.SelectedIndex]);

                //    }
                //    if (GlobalVar.motionConfig.cutParma2 == null)
                //        GlobalVar.motionConfig.cutParma2 = new CutParma();
                //    Set_Cut(GlobalVar.motionConfig.cutParma2);

                //    #endregion
                //    #region 圆检测
                //    if (GlobalVar.motionConfig.CircleFindCheck2 == null)
                //        GlobalVar.motionConfig.CircleFindCheck2 = new List<CircleFindParam>();
                //    var c_arr = Enum.GetNames(typeof(e_Line));
                //    for (int n = GlobalVar.motionConfig.CircleFindCheck2.Count; n < c_arr.Length; n++)
                //    {
                //        GlobalVar.motionConfig.CircleFindCheck2.Add(new CircleFindParam());
                //    }
                //    Set_CircleParam(GlobalVar.motionConfig.CircleFindCheck2[0]);
                //    #endregion
                //}
                //if (GlobalVar.motionConfig.posAfterLabel == null)
                //    GlobalVar.motionConfig.posAfterLabel = new VisionPostion();

                //if (rbn_m_Plate1.Checked)
                //{
                //    nud_p_grayMin.Value = (decimal)GlobalVar.motionConfig.posAfterLabel.grayMin1;
                //    nud_p_grayMax.Value = (decimal)GlobalVar.motionConfig.posAfterLabel.grayMax1;
                //    nud_p_AreaMin.Value = (decimal)GlobalVar.motionConfig.posAfterLabel.areaMin1;
                //    nud_p_AreaMax.Value = (decimal)GlobalVar.motionConfig.posAfterLabel.areaMax1;
                //}
                //else
                //{
                //    nud_p_grayMin.Value = (decimal)GlobalVar.motionConfig.posAfterLabel.grayMin2;
                //    nud_p_grayMax.Value = (decimal)GlobalVar.motionConfig.posAfterLabel.grayMax2;
                //    nud_p_AreaMin.Value = (decimal)GlobalVar.motionConfig.posAfterLabel.areaMin2;
                //    nud_p_AreaMax.Value = (decimal)GlobalVar.motionConfig.posAfterLabel.areaMax2;
                //}
                

                //nud_p_pixXreal.Value = (decimal)GlobalVar.motionConfig.posAfterLabel.pixXReal;
                //nud_p_pixYreal.Value = (decimal)GlobalVar.motionConfig.posAfterLabel.pixYReal;
                //nud_p_realX1.Value = (decimal)GlobalVar.motionConfig.posAfterLabel.RealX1;
                //nud_p_realX2.Value = (decimal)GlobalVar.motionConfig.posAfterLabel.RealX2;
                //nud_p_realY1.Value = (decimal)GlobalVar.motionConfig.posAfterLabel.RealY1;
                //nud_p_realY2.Value = (decimal)GlobalVar.motionConfig.posAfterLabel.RealY2;
                //nud_p_realR1.Value = (decimal)GlobalVar.motionConfig.posAfterLabel.RealR1;
                //nud_p_realR2.Value = (decimal)GlobalVar.motionConfig.posAfterLabel.RealR2;
             

                //ckb_isCircleCheck.Checked = GlobalVar.motionConfig.IsEnableCircleCheck;
                //rbt_dir_NGCheck.Text = GlobalVar.motionConfig.dir_CheckNG;
                //rbt_dir_OKCheck.Text = GlobalVar.motionConfig.dir_CheckOK;
            
                #endregion
                #endregion
                #region 读卡器
                if (GlobalVar.motionConfig.boxReadInfo == null)
                    GlobalVar.motionConfig.boxReadInfo = new BoxReadInfo();
                tbx_r_RM.Text = GlobalVar.motionConfig.boxReadInfo.MR;
                tbx_r_NGNG.Text = GlobalVar.motionConfig.boxReadInfo.NGNG;
                tbx_r_NGOK.Text = GlobalVar.motionConfig.boxReadInfo.NGOK;
                tbx_r_OK.Text = GlobalVar.motionConfig.boxReadInfo.OK;
                nud_r_StartAddress1.Value = GlobalVar.motionConfig.boxReadInfo.StartAddress1;
                nud_r_StartAddress2.Value = GlobalVar.motionConfig.boxReadInfo.StartAddress2;
                nud_r_station.Value = GlobalVar.motionConfig.boxReadInfo.station;
                nud_r_dataLength.Value = GlobalVar.motionConfig.boxReadInfo.dataLength;
                ckb_IsEnableR.Checked = GlobalVar.motionConfig.boxReadInfo.IsEnable;
                ckb_isReadWriteOK.Checked = GlobalVar.motionConfig.boxReadInfo.IsReadWriteOK;
                nud_r_ntimes.Value = GlobalVar.motionConfig.boxReadInfo.nTimes;
                tbx_r_NGflag.Text = GlobalVar.motionConfig.boxReadInfo.NGflag;
                nud_r_NumberEnd.Value = GlobalVar.motionConfig.boxReadInfo.NumberEnd;
                nud_r_NumberStart.Value = GlobalVar.motionConfig.boxReadInfo.NumberStart;
                ckb_r_IsNumber.Checked = GlobalVar.motionConfig.boxReadInfo.IsCheckNumber;
                nud_r_dataMinLength.Value = GlobalVar.motionConfig.boxReadInfo.minLength;

                tbx_r_havestring.Text = GlobalVar.motionConfig.boxReadInfo.have_string;
                tbx_r_p.Text = GlobalVar.motionConfig.boxReadInfo.have_P;
                tbx_r_O.Text = GlobalVar.motionConfig.boxReadInfo.have_O;
                tbx_r_R.Text = GlobalVar.motionConfig.boxReadInfo.have_R;
                nud_r_havecount.Value = GlobalVar.motionConfig.boxReadInfo.have_OPcount;
                ckb_IsCheckInclude.Checked = GlobalVar.motionConfig.boxReadInfo.IsCheckInclude;
                tbx_rfid_mode.Text = GlobalVar.motionConfig.rfid_mode;
                #endregion
            }
            catch (Exception ex)
            {
                displalyInfo.displayInfoMain?.Invoke($"ControlToParameter error : {ex}");
            }
        }
        private int UpdateCutPos(e_PosCut e_Pos)
        {
            try
            {
                switch (e_Pos)
                {
                    case e_PosCut.撕膜等料位:
                        nud_cut_WaitX.Value = (decimal)GlobalVar.motionConfig.Cut_pos[(int)e_PosCut.撕膜等料位].X;
                        nud_cut_WaitY.Value = (decimal)GlobalVar.motionConfig.Cut_pos[(int)e_PosCut.撕膜等料位].Y;
                        nud_cut_WaitZ.Value = (decimal)GlobalVar.motionConfig.Cut_pos[(int)e_PosCut.撕膜等料位].Z;
                        nud_cut_WaitR1.Value = (decimal)GlobalVar.motionConfig.Cut_pos[(int)e_PosCut.撕膜等料位].R1;
                        nud_cut_WaitR2.Value = (decimal)GlobalVar.motionConfig.Cut_pos[(int)e_PosCut.撕膜等料位].R2;
                        break;
                    case e_PosCut.撕膜水平位:

                        nud_cut_ProX.Value = (decimal)GlobalVar.motionConfig.Cut_pos[(int)e_PosCut.撕膜水平位].X;
                        nud_cut_ProY.Value = (decimal)GlobalVar.motionConfig.Cut_pos[(int)e_PosCut.撕膜水平位].Y;
                        nud_cut_ProZ.Value = (decimal)GlobalVar.motionConfig.Cut_pos[(int)e_PosCut.撕膜水平位].Z;
                        nud_cut_ProR1.Value = (decimal)GlobalVar.motionConfig.Cut_pos[(int)e_PosCut.撕膜水平位].R1;
                        nud_cut_ProR2.Value = (decimal)GlobalVar.motionConfig.Cut_pos[(int)e_PosCut.撕膜水平位].R2;
                        break;
                    case e_PosCut.夹膜位:
                        nud_cut_ClampX.Value = (decimal)GlobalVar.motionConfig.Cut_pos[(int)e_PosCut.夹膜位].X;
                        nud_cut_ClampY.Value = (decimal)GlobalVar.motionConfig.Cut_pos[(int)e_PosCut.夹膜位].Y;
                        nud_cut_ClampZ.Value = (decimal)GlobalVar.motionConfig.Cut_pos[(int)e_PosCut.夹膜位].Z;
                        nud_cut_ClampR1.Value = (decimal)GlobalVar.motionConfig.Cut_pos[(int)e_PosCut.夹膜位].R1;
                        nud_cut_ClampR2.Value = (decimal)GlobalVar.motionConfig.Cut_pos[(int)e_PosCut.夹膜位].R2;
                        break;
                    case e_PosCut.撕膜终点位:
                        nud_cut_EndX.Value = (decimal)GlobalVar.motionConfig.Cut_pos[(int)e_PosCut.撕膜终点位].X;
                        nud_cut_EndY.Value = (decimal)GlobalVar.motionConfig.Cut_pos[(int)e_PosCut.撕膜终点位].Y;
                        nud_cut_EndZ.Value = (decimal)GlobalVar.motionConfig.Cut_pos[(int)e_PosCut.撕膜终点位].Z;
                        nud_cut_EndR1.Value = (decimal)GlobalVar.motionConfig.Cut_pos[(int)e_PosCut.撕膜终点位].R1;
                        nud_cut_EndR2.Value = (decimal)GlobalVar.motionConfig.Cut_pos[(int)e_PosCut.撕膜终点位].R2;
                        break;
                    case e_PosCut.撕膜过度位:
                        nud_cut_mediumX.Value = (decimal)GlobalVar.motionConfig.Cut_pos[(int)e_PosCut.撕膜过度位].X;
                        nud_cut_mediumY.Value = (decimal)GlobalVar.motionConfig.Cut_pos[(int)e_PosCut.撕膜过度位].Y;
                        nud_cut_mediumZ.Value = (decimal)GlobalVar.motionConfig.Cut_pos[(int)e_PosCut.撕膜过度位].Z;
                        nud_cut_mediumR1.Value = (decimal)GlobalVar.motionConfig.Cut_pos[(int)e_PosCut.撕膜过度位].R1;
                        nud_cut_mediumR2.Value = (decimal)GlobalVar.motionConfig.Cut_pos[(int)e_PosCut.撕膜过度位].R2;
                        break;
                    case e_PosCut.撕膜垃圾位:
                        nud_cut_NGX.Value = (decimal)GlobalVar.motionConfig.Cut_pos[(int)e_PosCut.撕膜垃圾位].X;
                        nud_cut_NGY.Value = (decimal)GlobalVar.motionConfig.Cut_pos[(int)e_PosCut.撕膜垃圾位].Y;
                        nud_cut_NGZ.Value = (decimal)GlobalVar.motionConfig.Cut_pos[(int)e_PosCut.撕膜垃圾位].Z;
                        nud_cut_NGR1.Value = (decimal)GlobalVar.motionConfig.Cut_pos[(int)e_PosCut.撕膜垃圾位].R1;
                        nud_cut_NGR2.Value = (decimal)GlobalVar.motionConfig.Cut_pos[(int)e_PosCut.撕膜垃圾位].R2;
                        break;
                    case e_PosCut.撕膜安全位:
                        nud_cut_SafeX.Value = (decimal)GlobalVar.motionConfig.Cut_pos[(int)e_PosCut.撕膜安全位].X;
                        nud_cut_SafeY.Value = (decimal)GlobalVar.motionConfig.Cut_pos[(int)e_PosCut.撕膜安全位].Y;
                        nud_cut_SafeZ.Value = (decimal)GlobalVar.motionConfig.Cut_pos[(int)e_PosCut.撕膜安全位].Z;
                        nud_cut_SafeR1.Value = (decimal)GlobalVar.motionConfig.Cut_pos[(int)e_PosCut.撕膜安全位].R1;
                        nud_cut_SafeR2.Value = (decimal)GlobalVar.motionConfig.Cut_pos[(int)e_PosCut.撕膜安全位].R2;
                        break;
                }
                return 1;
            }catch(Exception ex)
            {
                displalyInfo.displayErrorMain(ex.Message);
                return -1;
            }
        }
        private int UpdateLabelPos(e_Pos e_Pos,e_platePro e_Plate)
        {
            try
            {
                var posList = new List<AbsPostion>();
                if (e_Plate == e_platePro.平台1)
                    posList = GlobalVar.motionConfig.Plate1_pos;
                else if (e_Plate == e_platePro.平台2)
                    posList = GlobalVar.motionConfig.Plate2_pos;
                switch (e_Pos)
                {
                    case e_Pos.飞达取标位:
                        nud_GetLabelX.Value = (decimal)posList[(int)e_Pos.飞达取标位].X;
                        nud_GetLabelY.Value = (decimal)posList[(int)e_Pos.飞达取标位].Y;
                        nud_GetLabelZ.Value = (decimal)posList[(int)e_Pos.飞达取标位].Z;
                        nud_GetLabelZHeight.Value = (decimal)posList[(int)e_Pos.飞达取标位].ZHeight;
                        nud_GetLabelR.Value = (decimal)posList[(int)e_Pos.飞达取标位].R;
                        break;
                    case e_Pos.拍照位:
                        nud_pos_scanX.Value = (decimal)posList[(int)e_Pos.拍照位].X;
                        nud_pos_scanY.Value = (decimal)posList[(int)e_Pos.拍照位].Y;
                        nud_pos_scanZ.Value = (decimal)posList[(int)e_Pos.拍照位].Z;
                        nud_pos_scanR.Value = (decimal)posList[(int)e_Pos.拍照位].R;
                        break;
                    case e_Pos.拍照检测位:

                        nud_pos_ResultY.Value = (decimal)posList[(int)e_Pos.拍照检测位].Y;
                        break;
                    case e_Pos.NG放标位:
                        nud_pos_NGX.Value = (decimal)posList[(int)e_Pos.NG放标位].X;
                        nud_pos_NGY.Value = (decimal)posList[(int)e_Pos.NG放标位].Y;
                        nud_pos_NGZ.Value = (decimal)posList[(int)e_Pos.NG放标位].Z;
                        nud_pos_NGZHeight.Value = (decimal)posList[(int)e_Pos.NG放标位].ZHeight;
                        nud_pos_NGR.Value = (decimal)posList[(int)e_Pos.NG放标位].R;
                        break;
                    case e_Pos.OK放标位:
                        nud_pos_OKX.Value = (decimal)posList[(int)e_Pos.OK放标位].X;
                        nud_pos_OKY.Value = (decimal)posList[(int)e_Pos.OK放标位].Y;
                        nud_pos_OKZ.Value = (decimal)posList[(int)e_Pos.OK放标位].Z;
                        nud_pos_OKZHeight.Value = (decimal)posList[(int)e_Pos.OK放标位].ZHeight;
                        nud_pos_OKR.Value = (decimal)posList[(int)e_Pos.OK放标位].R;
                        break;
                }
                return 1;
            }
            catch (Exception ex)
            {
                displalyInfo.displayErrorMain(ex.Message);
                return -1;
            }
        }
        private void ControlToParameter()
        {
            try
            {
                if (GlobalVar.motionConfig == null)
                {
                    GlobalVar.motionConfig = new MotionConfig();
                }

            
                #region 撕膜
                if (GlobalVar.motionConfig.Cut_pos == null|| GlobalVar.motionConfig.Cut_pos.Count< Enum.GetNames(typeof(e_PosCut)).Length)
                {
                    GlobalVar.motionConfig.Cut_pos = new List<CutPostion>();
                    var posCutCount = Enum.GetNames(typeof(e_PosCut)).Length;
                    for (int p = 0; p < posCutCount; p++)
                    {
                        GlobalVar.motionConfig.Cut_pos.Add(new CutPostion());
                    }
                }
                GlobalVar.motionConfig.Cut_pos[(int)e_PosCut.撕膜等料位].X = (double)nud_cut_WaitX.Value;
                GlobalVar.motionConfig.Cut_pos[(int)e_PosCut.撕膜等料位].Y = (double)nud_cut_WaitY.Value;
                GlobalVar.motionConfig.Cut_pos[(int)e_PosCut.撕膜等料位].Z = (double)nud_cut_WaitZ.Value;
                GlobalVar.motionConfig.Cut_pos[(int)e_PosCut.撕膜等料位].R1 = (double)nud_cut_WaitR1.Value;
                GlobalVar.motionConfig.Cut_pos[(int)e_PosCut.撕膜等料位].R2 = (double)nud_cut_WaitR2.Value;

                GlobalVar.motionConfig.Cut_pos[(int)e_PosCut.撕膜水平位].X = (double)nud_cut_ProX.Value;
                GlobalVar.motionConfig.Cut_pos[(int)e_PosCut.撕膜水平位].Y = (double)nud_cut_ProY.Value;
                GlobalVar.motionConfig.Cut_pos[(int)e_PosCut.撕膜水平位].Z = (double)nud_cut_ProZ.Value;
                GlobalVar.motionConfig.Cut_pos[(int)e_PosCut.撕膜水平位].R1 = (double)nud_cut_ProR1.Value;
                GlobalVar.motionConfig.Cut_pos[(int)e_PosCut.撕膜水平位].R2 = (double)nud_cut_ProR2.Value;

                GlobalVar.motionConfig.Cut_pos[(int)e_PosCut.夹膜位].X = (double)nud_cut_ClampX.Value;
                GlobalVar.motionConfig.Cut_pos[(int)e_PosCut.夹膜位].Y = (double)nud_cut_ClampY.Value;
                GlobalVar.motionConfig.Cut_pos[(int)e_PosCut.夹膜位].Z = (double)nud_cut_ClampZ.Value;
                GlobalVar.motionConfig.Cut_pos[(int)e_PosCut.夹膜位].R1 = (double)nud_cut_ClampR1.Value;
                GlobalVar.motionConfig.Cut_pos[(int)e_PosCut.夹膜位].R2 = (double)nud_cut_ClampR2.Value;

                GlobalVar.motionConfig.Cut_pos[(int)e_PosCut.撕膜过度位].X = (double)nud_cut_mediumX.Value;
                GlobalVar.motionConfig.Cut_pos[(int)e_PosCut.撕膜过度位].Y = (double)nud_cut_mediumY.Value;
                GlobalVar.motionConfig.Cut_pos[(int)e_PosCut.撕膜过度位].Z = (double)nud_cut_mediumZ.Value;
                GlobalVar.motionConfig.Cut_pos[(int)e_PosCut.撕膜过度位].R1 = (double)nud_cut_mediumR1.Value;
                GlobalVar.motionConfig.Cut_pos[(int)e_PosCut.撕膜过度位].R2 = (double)nud_cut_mediumR2.Value;

                GlobalVar.motionConfig.Cut_pos[(int)e_PosCut.撕膜终点位].X = (double)nud_cut_EndX.Value;
                GlobalVar.motionConfig.Cut_pos[(int)e_PosCut.撕膜终点位].Y = (double)nud_cut_EndY.Value;
                GlobalVar.motionConfig.Cut_pos[(int)e_PosCut.撕膜终点位].Z = (double)nud_cut_EndZ.Value;
                GlobalVar.motionConfig.Cut_pos[(int)e_PosCut.撕膜终点位].R1 = (double)nud_cut_EndR1.Value;
                GlobalVar.motionConfig.Cut_pos[(int)e_PosCut.撕膜终点位].R2 = (double)nud_cut_EndR2.Value;

                GlobalVar.motionConfig.Cut_pos[(int)e_PosCut.撕膜垃圾位].X = (double)nud_cut_NGX.Value;
                GlobalVar.motionConfig.Cut_pos[(int)e_PosCut.撕膜垃圾位].Y = (double)nud_cut_NGY.Value;
                GlobalVar.motionConfig.Cut_pos[(int)e_PosCut.撕膜垃圾位].Z = (double)nud_cut_NGZ.Value;
                GlobalVar.motionConfig.Cut_pos[(int)e_PosCut.撕膜垃圾位].R1 = (double)nud_cut_NGR1.Value;
                GlobalVar.motionConfig.Cut_pos[(int)e_PosCut.撕膜垃圾位].R2 = (double)nud_cut_NGR2.Value;

                GlobalVar.motionConfig.Cut_pos[(int)e_PosCut.撕膜安全位].X = (double)nud_cut_SafeX.Value;
                GlobalVar.motionConfig.Cut_pos[(int)e_PosCut.撕膜安全位].Y = (double)nud_cut_SafeY.Value;
                GlobalVar.motionConfig.Cut_pos[(int)e_PosCut.撕膜安全位].Z = (double)nud_cut_SafeZ.Value;
                GlobalVar.motionConfig.Cut_pos[(int)e_PosCut.撕膜安全位].R1 = (double)nud_cut_SafeR1.Value;
                GlobalVar.motionConfig.Cut_pos[(int)e_PosCut.撕膜安全位].R2 = (double)nud_cut_SafeR2.Value;

                GlobalVar.motionConfig.ProZ_down = (double)nud_downProZ.Value;
                GlobalVar.motionConfig.ProZ_up = (double)nud_upProZ.Value;

                GlobalVar.motionConfig.clamp_Delay = (double)nud_clamp_delay.Value;

                GlobalVar.motionConfig.CutNG_HeightZ = (double)nud_cut_NGZHeight.Value;
                GlobalVar.motionConfig.CutNG_LowZ = (double)nud_cut_NGZLow.Value;
                GlobalVar.motionConfig.CutNG_time = (int)nud_cut_NGZTime.Value;
                GlobalVar.motionConfig.CutNG_Delay = (int)nud_cut_NGZDelay.Value;
                GlobalVar.motionConfig.airCutTime = (int)nud_airCutTime.Value;

                #endregion
                #region 吸放标

                if (rbn_plate1.Checked)
                {
                    GlobalVar.motionConfig.Plate1_pos = GetPos();
                }
                else
                {
                    GlobalVar.motionConfig.Plate2_pos = GetPos();
                }
                if (GlobalVar.motionConfig.LaserNG_pos == null)
                {
                    GlobalVar.motionConfig.LaserNG_pos = new List<NGPostion>();
                    for (int p = 0; p < posNGCount; p++)
                    {
                        GlobalVar.motionConfig.LaserNG_pos.Add(new NGPostion());
                    }
                }
                GlobalVar.motionConfig.VisionPath = textBox3.Text;

                GlobalVar.motionConfig.LaserNG_pos[(int)e_PosNG.NG取工装位].Y = (double)nud_NGGetY.Value;
                GlobalVar.motionConfig.LaserNG_pos[(int)e_PosNG.NG取工装位].Zup = (double)nud_NGGetZup.Value;
                GlobalVar.motionConfig.LaserNG_pos[(int)e_PosNG.NG取工装位].Zdown = (double)nud_NGGetZdown.Value;

                GlobalVar.motionConfig.LaserNG_pos[(int)e_PosNG.NG放工装位].Y = (double)nud_NGPutY.Value;
                GlobalVar.motionConfig.LaserNG_pos[(int)e_PosNG.NG放工装位].Zup = (double)nud_NGPutZup.Value;
                GlobalVar.motionConfig.LaserNG_pos[(int)e_PosNG.NG放工装位].Zdown = (double)nud_NGPutZdown.Value;

                GlobalVar.motionConfig.scanSafeX1 = (double)nud_scanSafeX1.Value;
                GlobalVar.motionConfig.scanSafeX2 = (double)nud_scanSafeX2.Value;

                GlobalVar.motionConfig.NGlabelZ = (double)nud_NGLabelZ.Value;
                GlobalVar.motionConfig.checkPosY = (double)nud_checkPosY.Value;
                GlobalVar.motionConfig.Up_checkPosY = (double)nud_UpcheckPosY.Value;
                GlobalVar.motionConfig.Down_checkPosY = (double)nud_DowncheckPosY.Value;

                #endregion
                #region 飞达
                GlobalVar.motionConfig.delayFlyStop1 = (int)nud_delayStopFly1.Value;
                GlobalVar.motionConfig.delayFlyStop2 = (int)nud_delayStopFly2.Value;
                GlobalVar.motionConfig.Fly1TimeOutAlarm = (int)nud_Fly1TimeOutAlarm.Value;
                GlobalVar.motionConfig.Fly2TimeOutAlarm = (int)nud_Fly2TimeOutAlarm.Value;
                GlobalVar.motionConfig.FlyStop1 = (int)nud_flyStop1.Value;
                GlobalVar.motionConfig.FlyStop2 = (int)nud_flyStop2.Value;

                GlobalVar.motionConfig.fly1_AlarmCount = (int)nud_flyAlarmCount1.Value;
                GlobalVar.motionConfig.fly2_AlarmCount = (int)nud_flyAlarmCount2.Value;
                GlobalVar.motionConfig.fly1_Count = (int)nud_flyCount1.Value;
                GlobalVar.motionConfig.fly2_Count = (int)nud_flyCount2.Value;
                GlobalVar.motionConfig.flydelayCheck = (int)nud_flydelayCheck.Value;

                GlobalVar.motionConfig.fly1AngelEnd = (double)nud_flyAngleEnd1.Value;
                GlobalVar.motionConfig.fly1AngelStart = (double)nud_flyAngleStart1.Value;
                GlobalVar.motionConfig.fly1AngelUnit = (double)nud_flyAngleUnit1.Value;
                GlobalVar.motionConfig.fly2AngelEnd = (double)nud_flyAngleEnd2.Value;
                GlobalVar.motionConfig.fly2AngelStart = (double)nud_flyAngleStart2.Value;
                GlobalVar.motionConfig.fly2AngelUnit = (double)nud_flyAngleUnit2.Value;

                GlobalVar.motionConfig.fly1Updeley = (int)nud_fly1Updelay.Value;
                GlobalVar.motionConfig.fly2Updeley = (int)nud_fly2Updelay.Value;
                #endregion

                #region 图像处理
                //#region 模板定位
                //if (GlobalVar.motionConfig.visionBase1 == null)
                //    GlobalVar.motionConfig.visionBase1 = new VisionPos();
                //if (GlobalVar.motionConfig.visionBase2 == null)
                //    GlobalVar.motionConfig.visionBase2 = new VisionPos();
                //if (GlobalVar.motionConfig.TC_list == null)
                //{
                //    GlobalVar.motionConfig.TC_list = new List<TemplateParam>();
                //}
                //var tcount1 = Enum.GetNames(typeof(e_CameraPlate)).Length;
                //for (int i = GlobalVar.motionConfig.TC_list.Count; i < tcount1; i++)
                //{
                //    GlobalVar.motionConfig.TC_list.Add(new TemplateParam());
                //}
                //if (GlobalVar.motionConfig.TF_list == null)
                //{
                //    GlobalVar.motionConfig.TF_list = new List<TemplateFindParam>();
                //}

                //var tcount2 = Enum.GetNames(typeof(e_CameraPlate)).Length;
                //for (int i = GlobalVar.motionConfig.TF_list.Count; i < tcount2; i++)
                //{
                //    GlobalVar.motionConfig.TF_list.Add(new TemplateFindParam());
                //}
                //var curSelect = GetDrawSelect_T();
            
                //#endregion
                //#region 直线定位
                //if (GlobalVar.motionConfig.PosLindFind1 == null)
                //{
                //    GlobalVar.motionConfig.PosLindFind1 = new List<LindFindParam>();
                //}
                //if (GlobalVar.motionConfig.PosLindFind2 == null)
                //{
                //    GlobalVar.motionConfig.PosLindFind2 = new List<LindFindParam>();
                //}

                //var LCount = (int)e_Region.直线区域2 - (int)e_Region.直线区域1 + 1;
                //for (int i = GlobalVar.motionConfig.PosLindFind1.Count; i < LCount; i++)
                //{
                //    GlobalVar.motionConfig.PosLindFind1.Add(new LindFindParam());
                //}
                //for (int i = GlobalVar.motionConfig.PosLindFind2.Count; i < LCount; i++)
                //{
                //    GlobalVar.motionConfig.PosLindFind2.Add(new LindFindParam());
                //}

              
                //#endregion
                //#region 圆定位
                //if (GlobalVar.motionConfig.PosCircleFindCheck1 == null)
                //{
                //    GlobalVar.motionConfig.PosCircleFindCheck1 = new List<CircleFindParam>();
                //}
                //if (GlobalVar.motionConfig.PosCircleFindCheck2 == null)
                //{
                //    GlobalVar.motionConfig.PosCircleFindCheck2 = new List<CircleFindParam>();
                //}
                //var CCount = 1;
                //for (int i = GlobalVar.motionConfig.PosCircleFindCheck1.Count; i < CCount; i++)
                //{
                //    GlobalVar.motionConfig.PosCircleFindCheck1.Add(new CircleFindParam());
                //}
                //for (int i = GlobalVar.motionConfig.PosCircleFindCheck2.Count; i < CCount; i++)
                //{
                //    GlobalVar.motionConfig.PosCircleFindCheck2.Add(new CircleFindParam());
                //}
                //if (cbx_Region.SelectedIndex >= (int)e_Region.抓圆区域)
                //{
                //    if (curSelect == e_CameraPlate.定位相机平台1)
                //    {
                //        GlobalVar.motionConfig.PosCircleFindCheck1[cbx_Region.SelectedIndex - (int)e_Region.抓圆区域] = Get_CircleFindParam(GlobalVar.motionConfig.PosCircleFindCheck1[cbx_Region.SelectedIndex - (int)e_Region.抓圆区域]);
                //    }
                //    else if (curSelect == e_CameraPlate.定位相机平台2)
                //    {
                //        GlobalVar.motionConfig.PosCircleFindCheck2[cbx_Region.SelectedIndex - (int)e_Region.抓圆区域] = Get_CircleFindParam(GlobalVar.motionConfig.PosCircleFindCheck2[cbx_Region.SelectedIndex - (int)e_Region.抓圆区域]);
                //    }
                //}
                //#endregion

                //GlobalVar.motionConfig.TF_list[(int)curSelect] = Get_TemplateFind();
                //GlobalVar.motionConfig.TC_list[(int)curSelect] = Get_TemplateCreate();
                //#region 图案
                //if (curSelect == e_CameraPlate.图案相机平台1)
                //{
                //    GlobalVar.motionConfig.draw1 = GetDrawInfo();
                //}
                //else
                //{
                //    GlobalVar.motionConfig.draw2 = GetDrawInfo();
                //}
                //GlobalVar.motionConfig.dir_ScanNG = rbt_dir_NGDraw.Text;
                //GlobalVar.motionConfig.dir_ScanOK = rbt_dir_OKDraw.Text;
                //#endregion
                //if (rbn_m_Plate1.Checked)
                //{
                //    if (cbx_c_RegionSelect.SelectedIndex > -1)
                //    {
                //        GlobalVar.motionConfig.vision_M1_list[cbx_c_RegionSelect.SelectedIndex] = Get_Measure();

                //    }
                //    #region  直线检测
                //    GlobalVar.motionConfig.cutParma1 = Get_Cut();
                //    #endregion
                //    #region 圆检测
                //    if (GlobalVar.motionConfig.CircleFindCheck1 == null)
                //        GlobalVar.motionConfig.CircleFindCheck1 = new List<CircleFindParam>();
                //    var c_arr = Enum.GetNames(typeof(e_Circle));
                //    for (int n = GlobalVar.motionConfig.CircleFindCheck1.Count; n < c_arr.Length; n++)
                //    {
                //        GlobalVar.motionConfig.CircleFindCheck1.Add(new CircleFindParam());
                //    }
                //    if (cbx_c_RegionSelect.SelectedIndex >= (int)e_RegionCheck.找圆区域1 && cbx_c_RegionSelect.SelectedIndex <= (int)e_RegionCheck.找圆区域2)
                //    {
                //        GlobalVar.motionConfig.CircleFindCheck1[cbx_c_RegionSelect.SelectedIndex - (int)e_RegionCheck.找圆区域1] = Get_CircleParam(GlobalVar.motionConfig.CircleFindCheck1[cbx_c_RegionSelect.SelectedIndex - (int)e_RegionCheck.找圆区域1]);
                //    }
                //    #endregion
                //}
                //else
                //{
                //    if (cbx_c_RegionSelect.SelectedIndex > -1)
                //    {
                //        GlobalVar.motionConfig.vision_M2_list[cbx_c_RegionSelect.SelectedIndex] = Get_Measure();
                //    }
                //    #region 直线检测
                //    GlobalVar.motionConfig.cutParma2 = Get_Cut();

                //    #endregion
                //    #region 圆检测
                //    if (GlobalVar.motionConfig.CircleFindCheck2 == null)
                //        GlobalVar.motionConfig.CircleFindCheck2 = new List<CircleFindParam>();
                //    var c_arr = Enum.GetNames(typeof(e_Circle));
                //    for (int n = GlobalVar.motionConfig.CircleFindCheck2.Count; n < c_arr.Length; n++)
                //    {
                //        GlobalVar.motionConfig.CircleFindCheck2.Add(new CircleFindParam());
                //    }
                //    if (cbx_c_RegionSelect.SelectedIndex >= (int)e_RegionCheck.找圆区域1 && cbx_c_RegionSelect.SelectedIndex <= (int)e_RegionCheck.找圆区域2)
                //    {
                //        GlobalVar.motionConfig.CircleFindCheck2[cbx_c_RegionSelect.SelectedIndex - (int)e_RegionCheck.找圆区域1] = Get_CircleParam(GlobalVar.motionConfig.CircleFindCheck2[cbx_c_RegionSelect.SelectedIndex - (int)e_RegionCheck.找圆区域1]);
                //    }
                //    #endregion
                //}
                //GlobalVar.motionConfig.dir_CheckNG = rbt_dir_NGCheck.Text;
                //GlobalVar.motionConfig.dir_CheckOK = rbt_dir_OKCheck.Text;
                //#region 检测基准
                //if (GlobalVar.motionConfig.posAfterLabel == null)
                //    GlobalVar.motionConfig.posAfterLabel = new VisionPostion();
                //if (rbn_m_Plate1.Checked)
                //{
                //    GlobalVar.motionConfig.posAfterLabel.areaMax1 = (double)nud_p_AreaMax.Value;
                //    GlobalVar.motionConfig.posAfterLabel.areaMin1 = (double)nud_p_AreaMin.Value;
                //    GlobalVar.motionConfig.posAfterLabel.grayMax1 = (double)nud_p_grayMax.Value;
                //    GlobalVar.motionConfig.posAfterLabel.grayMin1 = (double)nud_p_grayMin.Value;
                //}
                //else
                //{
                //    GlobalVar.motionConfig.posAfterLabel.areaMax2 = (double)nud_p_AreaMax.Value;
                //    GlobalVar.motionConfig.posAfterLabel.areaMin2 = (double)nud_p_AreaMin.Value;
                //    GlobalVar.motionConfig.posAfterLabel.grayMax2 = (double)nud_p_grayMax.Value;
                //    GlobalVar.motionConfig.posAfterLabel.grayMin2 = (double)nud_p_grayMin.Value;
                //}
                
                //GlobalVar.motionConfig.posAfterLabel.pixXReal = (double)nud_p_pixXreal.Value;
                //GlobalVar.motionConfig.posAfterLabel.pixYReal = (double)nud_p_pixYreal.Value;
                //GlobalVar.motionConfig.posAfterLabel.RealX1 = (double)nud_p_realX1.Value;
                //GlobalVar.motionConfig.posAfterLabel.RealY1 = (double)nud_p_realY1.Value;
                //GlobalVar.motionConfig.posAfterLabel.RealR1 = (double)nud_p_realR1.Value;
                //GlobalVar.motionConfig.posAfterLabel.RealX2 = (double)nud_p_realX2.Value;
                //GlobalVar.motionConfig.posAfterLabel.RealY2 = (double)nud_p_realY2.Value;
                //GlobalVar.motionConfig.posAfterLabel.RealR2 = (double)nud_p_realR2.Value;
                //#endregion
       

                //GlobalVar.motionConfig.IsEnableCircleCheck = ckb_isCircleCheck.Checked;
                #endregion

                #region 读卡器
                if (GlobalVar.motionConfig.boxReadInfo == null)
                    GlobalVar.motionConfig.boxReadInfo = new BoxReadInfo();
                GlobalVar.motionConfig.boxReadInfo.dataLength = (int)nud_r_dataLength.Value;
                GlobalVar.motionConfig.boxReadInfo.NGNG = tbx_r_NGNG.Text;
                GlobalVar.motionConfig.boxReadInfo.MR = tbx_r_RM.Text;
                GlobalVar.motionConfig.boxReadInfo.station = (int)nud_r_station.Value;
                GlobalVar.motionConfig.boxReadInfo.StartAddress1 = (int)nud_r_StartAddress1.Value;
                GlobalVar.motionConfig.boxReadInfo.StartAddress2 = (int)nud_r_StartAddress2.Value;
                GlobalVar.motionConfig.boxReadInfo.NGOK = tbx_r_NGOK.Text;
                GlobalVar.motionConfig.boxReadInfo.OK = tbx_r_OK.Text;
                GlobalVar.motionConfig.boxReadInfo.IsReadWriteOK = ckb_isReadWriteOK.Checked;
                GlobalVar.motionConfig.boxReadInfo.IsEnable = ckb_IsEnableR.Checked;
                GlobalVar.motionConfig.boxReadInfo.nTimes = (int)nud_r_ntimes.Value;
                GlobalVar.motionConfig.boxReadInfo.NGflag = tbx_r_NGflag.Text.Trim();
                GlobalVar.motionConfig.boxReadInfo.NumberStart = (int)nud_r_NumberStart.Value;
                GlobalVar.motionConfig.boxReadInfo.NumberEnd = (int)nud_r_NumberEnd.Value;
                GlobalVar.motionConfig.boxReadInfo.IsCheckNumber = ckb_r_IsNumber.Checked;
                GlobalVar.motionConfig.boxReadInfo.minLength = (int)nud_r_dataMinLength.Value;
                GlobalVar.motionConfig.boxReadInfo.have_string = tbx_r_havestring.Text;
                GlobalVar.motionConfig.boxReadInfo.have_P = tbx_r_p.Text;
                GlobalVar.motionConfig.boxReadInfo.have_O = tbx_r_O.Text;
                GlobalVar.motionConfig.boxReadInfo.have_OPcount = (int)nud_r_havecount.Value;
                GlobalVar.motionConfig.boxReadInfo.IsCheckInclude = ckb_IsCheckInclude.Checked;
                GlobalVar.motionConfig.boxReadInfo.have_R = tbx_r_R.Text;
                GlobalVar.motionConfig.rfid_mode = tbx_rfid_mode.Text;
                #endregion
            }
            catch (Exception ex)
            {
                displalyInfo.displayInfoMain?.Invoke($"ControlToParameter error : {ex}");
            }
        }
        #region  类控件
       
        //private TemplateParam Get_TemplateCreate()
        //{
        //    var Template_Create = new TemplateParam();
        //    //Template_Create.eMetric = (e_Metric)Enum.Parse(typeof(e_Metric), cbx_tc_eMetric.Text.Trim());
        //    //Template_Create.eOptmization = (e_Optmization)Enum.Parse(typeof(e_Optmization), cbx_tc_eOptminzation.Text.Trim());
        //    //Template_Create.nContras = (int)nud_tc_Contra.Value;
        //    //Template_Create.nLevels = (int)nud_tc_nLevel.Value;
        //    //Template_Create.nMinContrast = (int)nud_tc_MinContra.Value;
        //    return Template_Create;
        //}
        //private void set_TemplateCreate(TemplateParam Template_Create)
        //{
        //    if (Template_Create == null)
        //        Template_Create = new TemplateParam();
        //    //cbx_tc_eMetric.Text = Template_Create.eMetric.ToString();
        //    //cbx_tc_eOptminzation.Text = Template_Create.eOptmization.ToString();
        //    //nud_tc_Contra.Value = Template_Create.nContras;
        //    //nud_tc_nLevel.Value = Template_Create.nLevels;
        //    //nud_tc_MinContra.Value = Template_Create.nMinContrast;
        //}
        //private TemplateFindParam Get_TemplateFind()
        //{
        //    var Template_Find = new TemplateFindParam();
        //    //Template_Find.nLevels = (int)nud_tf_Level.Value;
        //    ////Template_Find.dGreediness = (double)nud_tf_Greediness.Value;
        //    //Template_Find.dMaxOverlap = (double)nud_tf_MaxOverlap.Value;
        //    //Template_Find.dMinScore = (double)nud_tf_MinScore.Value;
        //    //Template_Find.nNumMatches = (int)nud_tf_NumMatch.Value;
        //    //Template_Find.eSubPixel = (e_SubPixel)Enum.Parse(typeof(e_SubPixel), cbx_tf_eSubPixel.Text.Trim());
        //    return Template_Find;
        //}
        //private void set_TemplateFind(TemplateFindParam Template_Find)
        //{
        //    if (Template_Find == null)
        //        Template_Find = new TemplateFindParam();
        //    //nud_tf_Level.Value = Template_Find.nLevels;
        //    ////nud_tf_Greediness.Value = (decimal)Template_Find.dGreediness;
        //    //nud_tf_MaxOverlap.Value = (decimal)Template_Find.dMaxOverlap;
        //    //nud_tf_MinScore.Value = (decimal)Template_Find.dMinScore;
        //    //nud_tf_NumMatch.Value = (decimal)Template_Find.nNumMatches;
        //    //cbx_tf_eSubPixel.Text = Template_Find.eSubPixel.ToString();
        //}
        //public drawInfo GetDrawInfo()
        //{
        //    //var curInfo = new drawInfo();
        //    //curInfo.d_AreaMax = (int)nud_d_AreaMax.Value;
        //    //curInfo.d_AreaMin = (int)nud_d_AreaMin.Value;
        //    //curInfo.d_grayMax = (int)nud_d_grayMax.Value;
        //    //curInfo.d_grayMin = (int)nud_d_grayMin.Value;
        //    //return curInfo;
        //}
        //public void SetDrawInfo(drawInfo curInfo)
        //{
        //    if (curInfo == null)
        //        curInfo = new drawInfo();
        //    //nud_d_AreaMax.Value = curInfo.d_AreaMax;
        //    //nud_d_AreaMin.Value = curInfo.d_AreaMin;
        //    //nud_d_grayMax.Value = curInfo.d_grayMax;
        //    //if (curInfo.d_grayMin > nud_d_grayMin.Maximum)
        //    //    curInfo.d_grayMin = (int)nud_d_grayMin.Maximum;
        //    //nud_d_grayMin.Value = curInfo.d_grayMin;

        //}
        //private CircleFindParam Get_CircleFindParam(CircleFindParam Lparam)
        //{
        //    if (Lparam == null)
        //        Lparam = new CircleFindParam();

        //    //Lparam.dSigma = (double)nud_tc_sigma.Value;
        //    //Lparam.dHalfWidth = (double)nud_tc_width.Value;
        //    //Lparam.dHalfLength = (double)nud_tc_length.Value;
        //    //Lparam.dThreshold = (int)nud_tc_Threshold.Value;
        //    //Lparam.dRadius = (double)nud_tc_radius.Value;
        //    //Lparam.point_order =cbx_tc_pointOrder.Text;
        //    //Lparam.dStartAngle = (double)nud_tc_startAngle.Value;
        //    //Lparam.dEndAngle = (double)nud_tc_EndAngle.Value;
        //    return Lparam;
        //}
       
        //private void Set_CircleParam(CircleFindParam param)
        //{
        //    //if (param == null)
        //    //    param = new CircleFindParam();

        //    //nud_c_sigma.Value = (decimal)param.dSigma;
        //    //nud_c_width.Value = (decimal)param.dHalfWidth;
        //    //nud_c_length.Value = (decimal)param.dHalfLength;
        //    //nud_c_Threshold.Value = (decimal)param.dThreshold;
        //    //nud_c_radius.Value = (decimal)param.dRadius;
        //    //cbx_c_pointOrder.Text = param.point_order;
        //    //nud_c_startAngle.Value = (decimal)param.dStartAngle;
        //    //nud_c_EndAngle.Value = (decimal)param.dEndAngle;
        //}
        //private CircleFindParam Get_CircleParam(CircleFindParam Lparam)
        //{
        //    //if (Lparam == null)
        //    //    Lparam = new CircleFindParam();

        //    //Lparam.dSigma = (double)nud_c_sigma.Value;
        //    //Lparam.dHalfWidth = (double)nud_c_width.Value;
        //    //Lparam.dHalfLength = (double)nud_c_length.Value;
        //    //Lparam.dThreshold = (int)nud_c_Threshold.Value;
        //    //Lparam.dRadius = (double)nud_c_radius.Value;
        //    //Lparam.point_order = cbx_c_pointOrder.Text;
        //    //Lparam.dStartAngle = (double)nud_c_startAngle.Value;
        //    //Lparam.dEndAngle = (double)nud_c_EndAngle.Value;
        //    //return Lparam;
        //}
        //private void Set_Measure(MeasureParma param)
        //{
        //    if (param == null)
        //        param = new MeasureParma();
        //    nud_m_Signal.Value = (decimal)param.dSigma;
        //    nud_m_Threshold.Value = (decimal)param.dThreshold;
        //    cbx_m_Interpolation.Text = param.Interpolation;
        //    cbx_m_Select.Text = param.Select;
        //    cbx_m_Transition.Text = param.Transition;
        //    nud_m_distanceMax.Value = (decimal)param.distanceMax;
        //    nud_m_distanceMin.Value = (decimal)param.distanceMin;
        //    nud_m_npar.Value = param.nPar;
        //}
        //private void Set_Cut(CutParma param)
        //{
        //    if (param == null)
        //        param = new CutParma();
        //    nud_m_AreaMax.Value = param.AreaMax;
        //    nud_m_AreaMin.Value = param.AreaMin;
        //    nud_m_grayMax.Value = param.GaryMax;
        //    nud_m_grayMin.Value = param.GaryMin;

        //}
        //private CutParma Get_Cut()
        //{
        //    var param = new CutParma();
        //    param.AreaMax = (int)nud_m_AreaMax.Value;
        //    param.AreaMin = (int)nud_m_AreaMin.Value;
        //    param.GaryMax = (int)nud_m_grayMax.Value;
        //    param.GaryMin = (int)nud_m_grayMin.Value;
        //    return param;
        //}
        //private MeasureParma Get_Measure()
        //{
        //    var param = new MeasureParma();
        //    param.RegionIndex = cbx_c_RegionSelect.SelectedIndex;
        //    param.dSigma = (double)nud_m_Signal.Value;
        //    param.dThreshold = (double)nud_m_Threshold.Value;
        //    param.Interpolation = cbx_m_Interpolation.Text;
        //    param.Select = cbx_m_Select.Text;
        //    param.Transition = cbx_m_Transition.Text;
        //    param.nPar = (int)nud_m_npar.Value;
        //    param.distanceMax = (double)nud_m_distanceMax.Value;
        //    param.distanceMin = (double)nud_m_distanceMin.Value;
        //    return param;
        //}
        #endregion

        private void btn_saveType_Click(object sender, EventArgs e)
        {
            var curType = cbo_type_selectType.Text.Trim();
            var curVersion = cbo_selectVersion.Text.Trim();
            if (!string.IsNullOrEmpty(curType) && !string.IsNullOrEmpty(curVersion))
            {
                var curTypeVer = curType + GlobalVar.char_VersionSpilt + curVersion;
                if (GlobalVar.closeSave.CurrentTypeName == curTypeVer)
                {

                    saveType(curType, curVersion);
                    displalyInfo.displayInfoMain("型号保存成功");
                }
                else
                {
                    displalyInfo.displayInfoMain($"已切换的配方{GlobalVar.closeSave.CurrentTypeName}与当前选中的配方{curTypeVer}不匹配  保存失败");
                }
            }
            
        }
        bool isFirst = true;
        //private void rbn_v_plate1_CheckedChanged(object sender, EventArgs e)
        //{
        //    var curSelect = GetDrawSelect_T();
        //    set_TemplateCreate(GlobalVar.motionConfig.TC_list[(int)curSelect]);
        //    set_TemplateFind(GlobalVar.motionConfig.TF_list[(int)curSelect]);
        //    if (curSelect == e_CameraPlate.图案相机平台1)
        //    {
        //        SetDrawInfo(GlobalVar.motionConfig.draw1);
        //    }
        //    else if (curSelect == e_CameraPlate.图案相机平台2)
        //    {
        //        SetDrawInfo(GlobalVar.motionConfig.draw2);
        //    }
        //}
        /// <summary>
        /// 
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        //private void rbn_m_Plate1_CheckedChanged(object sender, EventArgs e)
        //{
        //    GlobalVar.ChangeModel(GlobalVar.closeSave.CurrentTypeName);
        //    if (rbn_m_Plate1.Checked)
        //    {
        //        if (cbx_c_RegionSelect.SelectedIndex > -1)
        //        {
        //            if (GlobalVar.motionConfig.vision_M1_list != null && GlobalVar.motionConfig.vision_M1_list.Count > (cbx_c_RegionSelect.SelectedIndex + 1))
        //                Set_Measure(GlobalVar.motionConfig.vision_M1_list[cbx_c_RegionSelect.SelectedIndex]);
        //        }
        //        if (cbx_c_RegionSelect.SelectedIndex >= (int)e_RegionCheck.找圆区域1 && cbx_c_RegionSelect.SelectedIndex <= (int)e_RegionCheck.找圆区域2)//抓圆
        //        {
        //            Set_CircleParam(GlobalVar.motionConfig.CircleFindCheck1[cbx_c_RegionSelect.SelectedIndex - (int)e_RegionCheck.找圆区域1]);
        //        }
        //    }
        //    else
        //    {
        //        if (cbx_c_RegionSelect.SelectedIndex > -1)
        //        {
        //            if (GlobalVar.motionConfig.vision_M2_list != null && GlobalVar.motionConfig.vision_M2_list.Count > (cbx_c_RegionSelect.SelectedIndex + 1))
        //                Set_Measure(GlobalVar.motionConfig.vision_M2_list[cbx_c_RegionSelect.SelectedIndex]);
        //        }
        //        if (cbx_c_RegionSelect.SelectedIndex >= (int)e_RegionCheck.找圆区域1 && cbx_c_RegionSelect.SelectedIndex <= (int)e_RegionCheck.找圆区域2)//抓圆
        //        {
        //            Set_CircleParam(GlobalVar.motionConfig.CircleFindCheck2[cbx_c_RegionSelect.SelectedIndex - (int)e_RegionCheck.找圆区域1]);
        //        }
        //    }
        //    btn_m_ReadROI_Click(btn_m_ReadROI, null);
        //}
        private void rbn_plate1_CheckedChanged(object sender, EventArgs e)
        {
            if (rbn_plate1.Checked)
            {
                SetLabelLimit((int)e_platePro.平台1);
                SetPosList(GlobalVar.motionConfig.Plate1_pos);

            }
            else
            {
                SetLabelLimit((int)e_platePro.平台2);
                SetPosList(GlobalVar.motionConfig.Plate2_pos);

            }
        }
        private void PageType_Load(object sender, EventArgs e)
        {
            if (isFirst)
            {
                //GlobalVar.imageDisplay2 = ImageDisplay_2;
                //GlobalVar.imageDisplay2_obj = ImageDisplay_2_obj;
                //GlobalVar.Image_drawRoiRegion2 = DrawRoiRegion2;
                //GlobalVar.Image_clearRoiRegion2 = ClearRoiRegion2;

                //GlobalVar.imageDisplay3 = ImageDisplay_3;
                //GlobalVar.imageDisplay3_obj = ImageDisplay_3_obj;
                //GlobalVar.Image_drawRoiRegion3 = DrawRoiRegion3;
                //GlobalVar.Image_clearRoiRegion3 = ClearRoiRegion3;
                //cbx_m_Transition.SelectedIndex = 0;
                //cbx_m_Interpolation.SelectedIndex = 0;
                //cbx_m_Select.SelectedIndex = 0;
                //cbx_c_pointOrder.SelectedIndex = 1;
                //rbn_plate1.Checked = true;
                //rbn_plate2.Checked = false;
                //rbn_v_plate1.Checked = true;
                //rbn_v_plate2.Checked = false;
                //rbn_PosPlate1.Checked = true;
                this.rbn_plate1.CheckedChanged += new System.EventHandler(this.rbn_plate1_CheckedChanged);//点位切换平台
                //this.rbn_v_plate1.CheckedChanged += new System.EventHandler(this.rbn_v_plate1_CheckedChanged);//图案切换平台
                //this.rbn_m_Plate1.CheckedChanged -= new System.EventHandler(this.rbn_m_Plate1_CheckedChanged);//匹配对切换
                //rbn_m_Plate1.Checked = true;
                //this.rbn_m_Plate1.CheckedChanged += new System.EventHandler(this.rbn_m_Plate1_CheckedChanged);
                isFirst = false;
                SetCutLimit();
                Task.Factory.StartNew(Task_Status);
                var arr = Enum.GetNames(typeof(e_Pos));
                cbx_LabelPos.Items.AddRange(arr);
                var arr1 = Enum.GetNames(typeof(e_PosCut));
                cbx_CutPos.Items.AddRange(arr1);
              
                rbn_PosPlate1.CheckedChanged += Rbn_PosPlate1_CheckedChanged;
                rbn_PosPlate1.CheckedChanged += cbx_LabelPos_SelectedIndexChanged;
                rbn_PosPlate1.CheckedChanged += cbx_CutPos_SelectedIndexChanged;
                rbn_PosPlate1.BackColor = Color.Orange;
                //GlobalVar.RefreshModel += FreshVersionType;
            }
            posCount = Enum.GetNames(typeof(e_Pos)).Length;
            posNGCount = Enum.GetNames(typeof(e_PosNG)).Length;
            displalyInfo.displayInfoMain("型号数据初始化");
            GlobalVar.ChangeModel += ChangeModel;
            GlobalVar.ChangeModel(GlobalVar.closeSave.CurrentTypeName);

            //打开视觉软件嵌入窗体
            bool Result1 = false;
            PageMain.OpenVisionWindow(out Result1);

            if (rbn_plate1.Checked)
            {
                SetLabelLimit((int)e_platePro.平台1);
            }
            else
            {
                SetLabelLimit((int)e_platePro.平台2);
            }
           
        }

        private void Rbn_PosPlate1_CheckedChanged(object sender, EventArgs e)
        {
            rbn_PosPlate1.BackColor = rbn_PosPlate1.Checked ? Color.Orange : Color.Transparent;
            rbn_PosPlate2.BackColor = rbn_PosPlate2.Checked ? Color.Orange : Color.Transparent;
        }

        public int ChangeModel(string version)
        {
            try
            {
                //获取版本信息C0或C1
                if (version.Contains("C0"))
                {
                    GlobalMotion.Model_str = "C0";
                }
                else if (version.Contains("C1"))
                {
                    GlobalMotion.Model_str = "C1";
                }
                

                var typeVersion= GlobalVar.tv_list.Where(a => a.GetTypeVersion() == version).FirstOrDefault();
                if (typeVersion != null)
                {
                    this.cbo_type_selectType.SelectedIndexChanged -= new System.EventHandler(this.cbo_type_selectType_SelectedIndexChanged_1);
                    GlobalVar.motionConfig = (MotionConfig)SerializeHelper.DeserializeFile<MotionConfig>(GlobalVar.type_path + "\\" + version + ".tfp", "型号参数");//运动参数反序列化
                    this.Invoke(new Action(() =>
                    {
                        cbo_type_selectType.Text = typeVersion.type;
                        cbo_selectVersion.Text = typeVersion.Version;
                        ParameterToControl(version);
                    })
                     );
                    visionProc.ReadRegion_M(e_CameraPlate.检测相机平台1);
                    visionProc.ReadRegion_M(e_CameraPlate.检测相机平台2);
                    displalyInfo.displayInfoMain($"版本切换为{version }");
                    this.cbo_type_selectType.SelectedIndexChanged += new System.EventHandler(this.cbo_type_selectType_SelectedIndexChanged_1);
                    return 1;
                }
                else
                {
                    return -1;
                }
            }
            catch (Exception ex)
            {
                displalyInfo.displayErrorMain($"版本切换为{ GlobalVar.closeSave.CurrentTypeName }失败");
                return -1;
            }
        }


        #region 图案
        //private void cbx_c_RegionSelect_SelectedIndexChanged(object sender, EventArgs e)
        //{
        //    if (rbn_m_Plate1.Checked)
        //    {

        //            if (cbx_c_RegionSelect.SelectedIndex>-1&&cbx_c_RegionSelect.SelectedIndex <= visionProc.ROI_M_List1.Count)//设置匹配对
        //            {
        //                GlobalVar.imageDisplay3_obj(visionProc.ROI_M_List1[cbx_c_RegionSelect.SelectedIndex], "green");
        //                Set_Measure(GlobalVar.motionConfig.vision_M1_list[cbx_c_RegionSelect.SelectedIndex]);
        //            }
        //           if (cbx_c_RegionSelect.SelectedIndex >= (int)e_RegionCheck.找圆区域1 && cbx_c_RegionSelect.SelectedIndex <= (int)e_RegionCheck.找圆区域2)//抓圆
        //            {
        //                Set_CircleParam(GlobalVar.motionConfig.CircleFindCheck1[cbx_c_RegionSelect.SelectedIndex - (int)e_RegionCheck.找圆区域1]);
        //            }

        //    }
        //    else
        //    {

        //            if (cbx_c_RegionSelect.SelectedIndex > -1 && cbx_c_RegionSelect.SelectedIndex <= visionProc.ROI_M_List2.Count)//设置匹配对
        //            {
        //                GlobalVar.imageDisplay3_obj(visionProc.ROI_M_List2[cbx_c_RegionSelect.SelectedIndex], "green");
        //                Set_Measure(GlobalVar.motionConfig.vision_M2_list[cbx_c_RegionSelect.SelectedIndex]);
        //            }
        //            if (cbx_c_RegionSelect.SelectedIndex >= (int)e_RegionCheck.找圆区域1 && cbx_c_RegionSelect.SelectedIndex <= (int)e_RegionCheck.找圆区域2)//抓圆
        //            {
        //                Set_CircleParam(GlobalVar.motionConfig.CircleFindCheck2[cbx_c_RegionSelect.SelectedIndex - (int)e_RegionCheck.找圆区域1]);
        //            }


        //    }
        //}

        //private void btn_m_ReadROI_Click(object sender, EventArgs e)
        //{
        //    var curSelect = GetCheckSelect();
        //    var strArr = Enum.GetNames(typeof(e_RegionCheck));
        //    if (curSelect == e_CameraPlate.检测相机平台1)
        //    {
        //        visionProc.ROI_M_List1 = visionProc.ReadRegion_M(e_CameraPlate.检测相机平台1);
        //        if (visionProc.ROI_M_List1 != null && visionProc.ROI_M_List1.Count >= strArr.Length)
        //        {
        //            GlobalVar.imageDisplay3_obj?.Invoke(visionProc.ROI_M_List1[(int)e_RegionCheck.切图区域], "green");
        //            GlobalVar.imageDisplay3_obj?.Invoke(visionProc.ROI_M_List1[(int)e_RegionCheck.撕膜区域1], "red");
        //            GlobalVar.imageDisplay3_obj?.Invoke(visionProc.ROI_M_List1[(int)e_RegionCheck.撕膜区域2], "red");
        //            GlobalVar.imageDisplay3_obj?.Invoke(visionProc.ROI_M_List1[(int)e_RegionCheck.撕膜区域3], "red");
        //            GlobalVar.imageDisplay3_obj?.Invoke(visionProc.ROI_M_List1[(int)e_RegionCheck.检测区域1], "blue");
        //            GlobalVar.imageDisplay3_obj?.Invoke(visionProc.ROI_M_List1[(int)e_RegionCheck.检测区域2], "blue");
        //            GlobalVar.imageDisplay3_obj?.Invoke(visionProc.ROI_M_List1[(int)e_RegionCheck.检测区域3], "blue");
        //            GlobalVar.imageDisplay3_obj?.Invoke(visionProc.ROI_M_List1[(int)e_RegionCheck.检测区域4], "blue");
        //        }
        //    }
        //    else if (curSelect == e_CameraPlate.检测相机平台2)
        //    {
        //        visionProc.ROI_M_List2 = visionProc.ReadRegion_M(e_CameraPlate.检测相机平台2);
        //        if (visionProc.ROI_M_List2 != null && visionProc.ROI_M_List2.Count >= strArr.Length)
        //        {
        //            GlobalVar.imageDisplay3_obj?.Invoke(visionProc.ROI_M_List2[(int)e_RegionCheck.切图区域], "green");
        //            GlobalVar.imageDisplay3_obj?.Invoke(visionProc.ROI_M_List2[(int)e_RegionCheck.撕膜区域1], "red");
        //            GlobalVar.imageDisplay3_obj?.Invoke(visionProc.ROI_M_List2[(int)e_RegionCheck.撕膜区域2], "red");
        //            GlobalVar.imageDisplay3_obj?.Invoke(visionProc.ROI_M_List2[(int)e_RegionCheck.撕膜区域3], "red");
        //            GlobalVar.imageDisplay3_obj?.Invoke(visionProc.ROI_M_List2[(int)e_RegionCheck.检测区域1], "blue");
        //            GlobalVar.imageDisplay3_obj?.Invoke(visionProc.ROI_M_List2[(int)e_RegionCheck.检测区域2], "blue");
        //            GlobalVar.imageDisplay3_obj?.Invoke(visionProc.ROI_M_List2[(int)e_RegionCheck.检测区域3], "blue");
        //            GlobalVar.imageDisplay3_obj?.Invoke(visionProc.ROI_M_List2[(int)e_RegionCheck.检测区域4], "blue");
        //        }
        //    }
        //}


        // private void btn_ReadImage_Click(object sender, EventArgs e)
        // {
        //     try
        //     {
        //         OpenFileDialog ofd = new OpenFileDialog();
        //         ofd.Filter = "All File(*.*)|*.*";
        //         ofd.Title = "选择打印模板文件";
        //         ofd.InitialDirectory = Application.StartupPath;
        //         if (ofd.ShowDialog() == DialogResult.OK)
        //         {
        //             HOperatorSet.ReadImage(out HObject temp, ofd.FileName);
        //             HOperatorSet.MirrorImage(temp, out temp, "row");
        //             visionProc.srcObject_scan = temp;
        //             GlobalVar.imageDisplay2?.Invoke(visionProc.srcObject_scan);
        //             //Task.Run(() => {
        //             //    this.Invoke(new Action(()=> {
        //             //        pictureBox1.Image = rgbHobjectToBitmap(visionProc.srcObject_scan);

        //             //    }));

        //             //});


        //         }
        //     }
        //     catch (Exception ex)
        //     {
        //         displalyInfo.displayInfoMain($"{((Button)sender).Text}-[error] {ex.Message}");
        //     }
        // }
        // Bitmap rgbHobjectToBitmap(HObject imageObject)
        // {
        //     HOperatorSet.GetImagePointer1(imageObject, out HTuple hpoint, out HTuple type, out HTuple hwidth, out HTuple hHeight);
        //     HImage tempImage = new HImage(imageObject);
        ////     tempImage.GenImage1(type, hwidth, hHeight, hpoint);
        //     HImage grayImage = tempImage.Rgb1ToGray();//将彩色图像转为黑白
        //     IntPtr pointer = grayImage.GetImagePointer1(out type, out hwidth, out hHeight);
        //     ColorPalette palette = null;
        //     Bitmap bitmap = null;
        //     Bitmap curBitmap = new Bitmap(hwidth, hHeight, PixelFormat.Format8bppIndexed);
        //     Rectangle rect = new Rectangle(0, 0, curBitmap.Width, curBitmap.Height);
        //     BitmapData imageData = curBitmap.LockBits(rect, ImageLockMode.ReadOnly, curBitmap.PixelFormat);
        //     int PixelSize = Bitmap.GetPixelFormatSize(imageData.PixelFormat) / 8;
        //     //定义用于存储图像数据的Buffer
        //     byte[] buffer = new byte[curBitmap.Width * curBitmap.Height];
        //     //将图像数据复制到Buffer内
        //     System.Runtime.InteropServices.Marshal.Copy(pointer, buffer, 0, buffer.Length);
        //     unsafe
        //     {
        //         //使用不安全代码
        //         fixed (byte* bytePointer = buffer)
        //         {
        //             bitmap = new Bitmap(curBitmap.Width, curBitmap.Height, curBitmap.Width, PixelFormat.Format8bppIndexed, new IntPtr(bytePointer));
        //             palette = bitmap.Palette;
        //             for (int Index = 0; Index <= byte.MaxValue; Index++)
        //             {
        //                 palette.Entries[Index] = Color.FromArgb(byte.MaxValue, Index, Index, Index);
        //             }
        //             bitmap.Palette = palette;
        //             // bitmap.Save(@"C:\Users\15162\Desktop\bitmap.bmp");
        //         }
        //     }
        //     return bitmap;
        // }
        // private void btn_Draw_Click(object sender, EventArgs e)
        // {
        //     var curSelect = GetDrawSelect_T();
        //     if (curSelect == e_CameraPlate.图案相机平台1 || curSelect == e_CameraPlate.图案相机平台2)
        //         GlobalVar.Image_drawRoiRegion2();

        // }

        // private void btn_clearRoi_Click(object sender, EventArgs e)
        // {
        //     var curSelect = GetDrawSelect_T();
        //      if (curSelect == e_CameraPlate.图案相机平台1 || curSelect == e_CameraPlate.图案相机平台2)
        //         GlobalVar.Image_clearRoiRegion2();
        // }

        // private void btn_ReadROI_Click(object sender, EventArgs e)
        // {
        //     var curSelect = GetDrawSelect_T();
        //     visionProc.ReadRegion();
        //     if (curSelect == e_CameraPlate.图案相机平台1 || curSelect == e_CameraPlate.图案相机平台2)
        //     {
        //         visionProc.ROI2 = visionProc.ROI_List[(int)curSelect];
        //         GlobalVar.imageDisplay2_obj(visionProc.ROI2.ROI_Region, "green");
        //         GlobalVar.imageDisplay2_obj(visionProc.ROI2.ROI_Template, "blue");
        //     }
        // }

        // private void btn_SaveROI_Click(object sender, EventArgs e)
        // {
        //     var nRegion = cbx_Region.Items.IndexOf(cbx_Region.Text);
        //     if (nRegion > -1)
        //     {
        //         var arr = Enum.GetNames(typeof(e_Region));
        //         if (arr.Contains(cbx_Region.Text))
        //         {
        //             var curSelect = GetDrawSelect_T();
        //             //if(rbn_v_plate1.Checked)
        //             visionProc.SaveRegion((e_Region)Enum.Parse(typeof(e_Region), cbx_Region.Text), curSelect);
        //             displalyInfo.displayInfoMain($"{curSelect.ToString()}区域：{cbx_Region.Text} 保存成功");
        //             return;
        //         }
        //     }
        //     displalyInfo.displayErrorMain($"区域：{cbx_Region.Text}保存失败");
        // }


        //private void btn_m_readTemplateImage_Click(object sender, EventArgs e)
        //{
        //    try
        //    {
        //        OpenFileDialog ofd = new OpenFileDialog();
        //        ofd.Filter = "All File(*.*)|*.*";
        //        ofd.Title = "选择检测相机图片";
        //        ofd.InitialDirectory = Application.StartupPath;
        //        if (ofd.ShowDialog() == DialogResult.OK)
        //        {
        //            HOperatorSet.ReadImage(out visionProc.srcObject_ckeck, ofd.FileName);

        //            GlobalVar.imageDisplay3(visionProc.srcObject_ckeck);
        //        }
        //    }
        //    catch (Exception ex)
        //    {
        //        displalyInfo.displayInfoMain($"{((Button)sender).Text}-[error] {ex.Message}");
        //    }
        //}

        //private void btn_m_Draw_Click(object sender, EventArgs e)
        //{
        //    GlobalVar.Image_drawRoiRegion3();
        //}

        //private void btn_CreateTemplate_Click(object sender, EventArgs e)
        //{
        //    var curSelect = GetDrawSelect_T();
        //    var param = Get_TemplateCreate();
        //    if (curSelect == e_CameraPlate.图案相机平台1 || curSelect == e_CameraPlate.图案相机平台2)
        //        visionProc.TemplateIds[(int)curSelect] = visionProc.CreateTemplate(visionProc.srcObject_scan, visionProc.ROI2.ROI_Template, param, e_Camera.图案相机);
        //}

        //private void btn_ReadTemplate_Click(object sender, EventArgs e)
        //{
        //    visionProc.ReadTemplateRegion();
        //}

        //private void btn_SaveTemplate_Click(object sender, EventArgs e)
        //{
        //    var curSelect = GetDrawSelect_T();
        //    visionProc.SaveTemplateRegion(visionProc.TemplateIds[(int)curSelect], curSelect);
        //}

        //private void btn_reduce_Click(object sender, EventArgs e)
        //{
        //    visionProc.isReduce = true;
        //    visionProc.reduce_Radius = (int)nud_radiusReduce.Value;
        //}

        //private void btn_reduceOK_Click(object sender, EventArgs e)
        //{
        //    visionProc.isReduce = false;
        //}

        //private void btn_CheckTemplate_Click(object sender, EventArgs e)
        //{
        //    var select = GetDrawSelect_T();
        //    visionProc.TemplateParam_Find = Get_TemplateFind();
        //     if (select == e_CameraPlate.图案相机平台1 || select == e_CameraPlate.图案相机平台2)
        //    {
        //        HOperatorSet.ReduceDomain(visionProc.srcObject_scan, visionProc.ROI_List[(int)e_CameraPlate.图案相机平台1].ROI_Region, out HObject region_cut);
        //        HOperatorSet.Threshold(region_cut, out HObject AreaHobj, GlobalVar.motionConfig.draw1.d_grayMin, GlobalVar.motionConfig.draw1.d_grayMax);
        //        HOperatorSet.AreaCenter(AreaHobj, out HTuple hArea, out HTuple tempR, out HTuple tempC);
        //        if (hArea.Type != HTupleType.EMPTY)
        //        {
        //            var res = visionProc.findTemplate(visionProc.srcObject_scan, visionProc.TemplateIds[(int)select], visionProc.TemplateParam_Find, visionProc.ROI_List[(int)select].ROI_Region);
        //            if (res != null)
        //                displalyInfo.displayInfoMain(JsonConvert.SerializeObject(res));
        //        }
        //    }
        //}

        //private void btn_image_Click(object sender, EventArgs e)
        //{
        //    var curSelect = GetDrawSelect_T();
        //    visionProc.TemplateParam_Find = Get_TemplateFind();
        //    visionProc.ReadRegion();
        //    visionProc.curCameraPlate2 = curSelect;
        //    GlobalVar.cameraList[(int)e_Camera.图案相机].softTrigger();
        //}

        //private void cbx_Region_SelectedIndexChanged(object sender, EventArgs e)
        //{
        //    if (rbn_m_Plate1.Checked)
        //    {
        //        if (cbx_Region.SelectedIndex > -1 && cbx_Region.SelectedIndex <= visionProc.ROI_M_List1.Count)
        //            GlobalVar.imageDisplay3_obj(visionProc.ROI_M_List1[cbx_Region.SelectedIndex], "green");
        //        if (cbx_Region.SelectedIndex >= (int)e_RegionCheck.检测区域1) ;
        //        Set_Measure(GlobalVar.motionConfig.vision_M1_list[cbx_Region.SelectedIndex]);
        //        if (cbx_Region.SelectedIndex >= (int)e_RegionCheck.找圆区域1 && cbx_Region.SelectedIndex <= (int)e_RegionCheck.找圆区域2)
        //            Set_CircleParam(GlobalVar.motionConfig.CircleFindCheck1[cbx_Region.SelectedIndex - (int)e_RegionCheck.找圆区域1]);
        //    }
        //    else
        //    {
        //        if (cbx_Region.SelectedIndex > -1 && cbx_Region.SelectedIndex <= visionProc.ROI_M_List2.Count)
        //            GlobalVar.imageDisplay3_obj(visionProc.ROI_M_List2[cbx_Region.SelectedIndex], "green");
        //        if (cbx_Region.SelectedIndex >= (int)e_RegionCheck.检测区域1) ;
        //        Set_Measure(GlobalVar.motionConfig.vision_M2_list[cbx_Region.SelectedIndex]);
        //        if (cbx_Region.SelectedIndex >= (int)e_RegionCheck.找圆区域1 && cbx_Region.SelectedIndex <= (int)e_RegionCheck.找圆区域2)
        //            Set_CircleParam(GlobalVar.motionConfig.CircleFindCheck2[cbx_Region.SelectedIndex - (int)e_RegionCheck.找圆区域1]);

        //    }
        //}

        //private void cbo_type_selectType_SelectedIndexChanged(object sender, EventArgs e)
        //{
        //    //if (cbo_type_selectType.SelectedIndex > -1)
        //    //{
        //    //    var strSelect = cbo_type_selectType.Text;
        //    //    if (GlobalVar.closeSave.CurrentTypeName.StartsWith(strSelect + GlobalVar.char_VersionSpilt))
        //    //        return;
        //    //    var tList = GlobalVar.tv_list.Where(a => a.type == strSelect).ToList();
        //    //    if (tList.Count > 0)
        //    //    {
        //    //        cbo_selectVersion.Items.Clear();
        //    //        cbo_selectVersion.Items.AddRange(tList.Select(a => a.Version).ToArray());
        //    //        cbo_selectVersion.SelectedIndex = 0;
        //    //        var strVersion = cbo_selectVersion.Text;
        //    //        var curtypeVerison = strSelect + "~" + strVersion;
        //    //        GlobalVar.motionConfig = (MotionConfig)SerializeHelper.DeserializeFile<MotionConfig>(GlobalVar.type_path + "\\" + curtypeVerison + ".tfp", "型号参数");//运动参数反序列化
        //    //        ParameterToControl();
        //    //        GlobalVar.closeSave.CurrentTypeName = curtypeVerison;
        //    //    }
        //    //}
        //}

        //private void cbo_selectVersion_SelectedIndexChanged(object sender, EventArgs e)
        //{
        //    //if (cbo_type_selectType.SelectedIndex > -1 && cbo_selectVersion.SelectedIndex > -1)
        //    //{
        //    //    var strSelect = cbo_type_selectType.Text;
        //    //    var strVersion = cbo_selectVersion.Text;
        //    //    var tList = GlobalVar.tv_list.Where(a => a.type == strSelect && a.Version == strVersion).ToList();
        //    //    if (tList.Count > 0)
        //    //    {
        //    //        var curtypeVerison = tList[0].type + "~" + tList[0].Version;
        //    //        GlobalVar.motionConfig = (MotionConfig)SerializeHelper.DeserializeFile<MotionConfig>(GlobalVar.type_path + "\\" + curtypeVerison + ".tfp", "型号参数");//运动参数反序列化
        //    //        ParameterToControl();
        //    //        GlobalVar.closeSave.CurrentTypeName = curtypeVerison;
        //    //        displalyInfo.displayInfoMain($"版本切换为{ GlobalVar.closeSave.CurrentTypeName }");
        //    //    }
        //    //}
        //}

        //private void btn_m_SaveROI_Click(object sender, EventArgs e)
        //{
        //    var nRegion = cbx_c_RegionSelect.Items.IndexOf(cbx_c_RegionSelect.Text);
        //    if (nRegion > -1)
        //    {
        //        var arr = Enum.GetNames(typeof(e_RegionCheck));
        //        var curSelect = GetCheckSelect();
        //        visionProc.SaveRegion_M((e_RegionCheck)Enum.Parse(typeof(e_RegionCheck), arr[nRegion]), curSelect);
        //        displalyInfo.displayInfoMain($"{curSelect.ToString()}区域：{arr[nRegion]} 保存成功");
        //    }
        //}

        //private void btn_clearRegion_Click(object sender, EventArgs e)
        //{
        //    GlobalVar.Image_clearRoiRegion3();
        //}
        //private e_CameraPlate GetCheckSelect()
        //{
        //    var res = e_CameraPlate.检测相机平台1;
        //    if(rbn_m_Plate1.Checked)
        //        res = e_CameraPlate.检测相机平台1;
        //    else if (rbn_m_Plate2.Checked)
        //        res = e_CameraPlate.检测相机平台2;
        //    return res;
        //}
        //private void btn_m_plateTest_Click(object sender, EventArgs e)
        //{
        //    var curSelect = GetCheckSelect();
        //    GlobalVar.IsPosBeforeLabel = false;
        //    visionProc.visionProcCam(visionProc.srcObject_ckeck, curSelect);
        //}

        //private void btn_cameraTest_Click(object sender, EventArgs e)
        //{

        //}

        //private void button1_Click(object sender, EventArgs e)
        //{
        //    visionProc.curCameraPlate3 = GetCheckSelect();
        //    GlobalVar.cameraList[(int)e_Camera.检测相机].softTrigger();
        //}

        //private void button3_Click(object sender, EventArgs e)
        //{
        //    if (rbn_m_Plate1.Checked)
        //    {
        //        if (visionProc.pos1pix != null)
        //        {
        //            nud_p_realR1.Value = (decimal)visionProc.pos1pix.R;
        //            nud_p_realX1.Value = (decimal)visionProc.pos1pix.X;
        //            nud_p_realY1.Value = (decimal)visionProc.pos1pix.Y;
        //        }
        //    }
        //    else
        //    {
        //        if (visionProc.pos2pix != null)
        //        {
        //            nud_p_realR2.Value = (decimal)visionProc.pos2pix.R;
        //            nud_p_realX2.Value = (decimal)visionProc.pos2pix.X;
        //            nud_p_realY2.Value = (decimal)visionProc.pos2pix.Y;
        //        }
        //    }
        //}
        #endregion


        #region 读卡器
        private void btn_In1_Click(object sender, EventArgs e)
        {
            if (!GlobalVar.userConfig.RFIDBox.IsEnableRFID)
            {
                var resString = GlobalVar.Box1.ReadBoxString((int)nud_r_StartAddress1.Value, (int)nud_r_dataLength.Value, (int)nud_r_station.Value, ckb_isReadWriteOK.Checked);
                displalyInfo.displayInfoMain(resString);
            }else
            {
              var RES=  GlobalVar.RFIDBox_in.ReadRFID(GlobalVar.userConfig.RFIDBox.station, GlobalVar.motionConfig.rfid_mode);
            }
        }

        private void btn_In2_Click(object sender, EventArgs e)
        {
            if (!GlobalVar.userConfig.RFIDBox.IsEnableRFID)
            {
                var resString = GlobalVar.Box1.ReadBoxString((int)nud_r_StartAddress2.Value, (int)nud_r_dataLength.Value, (int)nud_r_station.Value, ckb_isReadWriteOK.Checked);
                displalyInfo.displayInfoMain(resString);
            }
            else
            {
                GlobalVar.RFIDBox_in.ReadRFID(GlobalVar.userConfig.RFIDBox.station, GlobalVar.motionConfig.rfid_mode);
            }
        }

        private void btn_Out1_Click(object sender, EventArgs e)
        {
            if (!GlobalVar.userConfig.RFIDBox.IsEnableRFID)
            {
                var resString = GlobalVar.Box2.WriteBoxString((int)nud_r_StartAddress1.Value, tbx_r_Content.Text.Trim(), (int)nud_r_station.Value, ckb_isReadWriteOK.Checked);
                displalyInfo.displayInfoMain(resString);
            }
            else
            {
                GlobalVar.RFIDBox_out.WriteRFID(GlobalVar.userConfig.RFIDBox.station, new string[] { "", "" }, new string[] { tbx_r_Content.Text.Trim(), tbx_r_Content.Text.Trim() });
            }

        }

        private void btn_Out2_Click(object sender, EventArgs e)
        {
            if (!GlobalVar.userConfig.RFIDBox.IsEnableRFID)
            {
                var resString = GlobalVar.Box2.WriteBoxString((int)nud_r_StartAddress2.Value, tbx_r_Content.Text.Trim(), (int)nud_r_station.Value, ckb_isReadWriteOK.Checked);
                displalyInfo.displayInfoMain(resString);
            }
            else
            {
                GlobalVar.RFIDBox_out.WriteRFID(GlobalVar.userConfig.RFIDBox.station, new string[] { "", "" }, new string[] { tbx_r_Content.Text.Trim(), tbx_r_Content.Text.Trim() });
            }
        }
        private void btn_In1_write_Click(object sender, EventArgs e)
        {
            if (!GlobalVar.userConfig.RFIDBox.IsEnableRFID)
            {
                var resString = GlobalVar.Box1.WriteBoxString((int)nud_r_StartAddress1.Value, tbx_r_Content.Text.Trim(), (int)nud_r_station.Value, ckb_isReadWriteOK.Checked);
                displalyInfo.displayInfoMain(resString);
            }
            else
            {
                GlobalVar.RFIDBox_in.WriteRFID(GlobalVar.userConfig.RFIDBox.station, new string[] { "", "" }, new string[] { tbx_r_Content.Text.Trim(), tbx_r_Content.Text.Trim() });
            }
        }

        private void btn_In2_write_Click(object sender, EventArgs e)
        {
            if (!GlobalVar.userConfig.RFIDBox.IsEnableRFID)
            {
                var resString = GlobalVar.Box1.WriteBoxString((int)nud_r_StartAddress2.Value, tbx_r_Content.Text.Trim(), (int)nud_r_station.Value, ckb_isReadWriteOK.Checked);
                displalyInfo.displayInfoMain(resString);
            }
            else
            {
                GlobalVar.RFIDBox_in.WriteRFID(GlobalVar.userConfig.RFIDBox.station, new string[] { "", "" }, new string[] { tbx_r_Content.Text.Trim(), tbx_r_Content.Text.Trim() });
            }
        }

        private void btn_Out1_read_Click(object sender, EventArgs e)
        {
            if (!GlobalVar.userConfig.RFIDBox.IsEnableRFID)
            {
                var resString = GlobalVar.Box2.ReadBoxString((int)nud_r_StartAddress1.Value, (int)nud_r_dataLength.Value, (int)nud_r_station.Value, ckb_isReadWriteOK.Checked);
                displalyInfo.displayInfoMain(resString);
            }
            else
            {
                GlobalVar.RFIDBox_out.ReadRFID(GlobalVar.userConfig.RFIDBox.station, GlobalVar.motionConfig.rfid_mode);
            }
        }

        private void btn_Out2_read_Click(object sender, EventArgs e)
        {
            if (!GlobalVar.userConfig.RFIDBox.IsEnableRFID)
            {
                var resString = GlobalVar.Box2.ReadBoxString((int)nud_r_StartAddress2.Value, (int)nud_r_dataLength.Value, (int)nud_r_station.Value, ckb_isReadWriteOK.Checked);
                displalyInfo.displayInfoMain(resString);
            }
            else
            {
                GlobalVar.RFIDBox_out.ReadRFID(GlobalVar.userConfig.RFIDBox.station, GlobalVar.motionConfig.rfid_mode);
            }
        }
        #endregion
        //private void btn_testPos_Click(object sender, EventArgs e)
        //{
        //    GlobalVar.IsPosBeforeLabel = true;
        //    GlobalVar.userConfig.IsPosAfterLabel = true;
        //    if (rbn_m_Plate1.Checked)
        //    {
        //        visionProc.visionProcCam(visionProc.srcObject_ckeck, e_CameraPlate.检测相机平台1);
        //    }
        //    else
        //    {
        //        visionProc.visionProcCam(visionProc.srcObject_ckeck, e_CameraPlate.检测相机平台2);
        //    }

        //    GlobalVar.userConfig.IsPosAfterLabel = false;
        //    GlobalVar.IsPosBeforeLabel = false;
        //}

        //private void btn_CameraCheck_Click(object sender, EventArgs e)
        //{
        //    GlobalVar.IsPosBeforeLabel = true;
        //    GlobalVar.IsLabelPosTwo = true;
        //    if (rbn_m_Plate1.Checked)
        //    {
        //        visionProc.CamIdx = 1;
        //    }
        //    else
        //    {
        //        visionProc.CamIdx = 2;
        //    }
        //    GlobalVar.cameraList[(int)e_Camera.检测相机].softTrigger();
        //}

        private void btn_Move_GetNGY_Click(object sender, EventArgs e)
        {
            GlobalMotion.Card_1.AxisList[(int)e_card1_axis.贴标Y轴].PointMove((double)nud_NGGetY.Value, true);
        }

        private void btn_Move_GetNGZHeight_Click(object sender, EventArgs e)
        {
            GlobalMotion.Card_1.AxisList[(int)e_card1_axis.剔除Z轴].PointMove((double)nud_NGGetZup.Value, true);
        }

        private void btn_Move_GetNGZlow_Click(object sender, EventArgs e)
        {
            GlobalMotion.Card_1.AxisList[(int)e_card1_axis.剔除Z轴].PointMove((double)nud_NGGetZdown.Value, true);
        }

        private void btn_Move_PutNGY_Click(object sender, EventArgs e)
        {
            GlobalMotion.Card_1.AxisList[(int)e_card1_axis.贴标Y轴].PointMove((double)nud_NGPutY.Value, true);
        }

        private void btn_Move_PutNGZHeight_Click(object sender, EventArgs e)
        {
            GlobalMotion.Card_1.AxisList[(int)e_card1_axis.剔除Z轴].PointMove((double)nud_NGPutZup.Value, true);
        }

        private void btn_Move_PutNGZLow_Click(object sender, EventArgs e)
        {
            GlobalMotion.Card_1.AxisList[(int)e_card1_axis.剔除Z轴].PointMove((double)nud_NGPutZdown.Value, true);
        }

        private void btn_Move_NGlabelZ_Click(object sender, EventArgs e)
        {
            GlobalMotion.Card_1.AxisList[(int)e_card1_axis.贴标Z轴].PointMove((double)nud_NGLabelZ.Value, true);
        }

        private void btn_move_scanSafeX1_Click(object sender, EventArgs e)
        {
            GlobalMotion.Card_1.AxisList[(int)e_card1_axis.贴标X1下].PointMove((double)nud_scanSafeX1.Value, true);
        }

        private void btn_move_scanSafeX2_Click(object sender, EventArgs e)
        {
            GlobalMotion.Card_1.AxisList[(int)e_card1_axis.贴标X2上].PointMove((double)nud_scanSafeX2.Value, true);
        }

        private void btn_move_CheckY_Click(object sender, EventArgs e)
        {
            GlobalMotion.Card_1.AxisList[(int)e_card1_axis.贴标Y轴].PointMove((double)nud_checkPosY.Value, true);
        }

        private void button1_Click(object sender, EventArgs e)
        {
            GlobalMotion.Card_1.AxisList[(int)e_card1_axis.贴标Y轴].PointMove((double)nud_UpcheckPosY.Value, true);
        }

        private void button2_Click(object sender, EventArgs e)
        {
            GlobalMotion.Card_1.AxisList[(int)e_card1_axis.贴标Y轴].PointMove((double)nud_DowncheckPosY.Value, true);
        }

        private void btn_upProZ_Click(object sender, EventArgs e)
        {
            GlobalMotion.Card_1.AxisList[(int)e_card1_axis.一段压产品Z].PointMove((double)nud_upProZ.Value, true);
        }

        private void btn_downProZ_Click(object sender, EventArgs e)
        {
            GlobalMotion.Card_1.AxisList[(int)e_card1_axis.一段压产品Z].PointMove((double)nud_downProZ.Value, true);
        }
        /// <summary>
        /// 点位
        /// </summary>
        /// <returns></returns>
        private e_platePro GetPosPlateSelect()
        {
            var res = e_platePro.双平台无;
            if (rbn_PosPlate1.Checked)
            {
                res = e_platePro.平台1;
            }
            else if (rbn_PosPlate2.Checked)
                res = e_platePro.平台2;

            return res;
        }
        private void btn_StepLabel_Click(object sender, EventArgs e)
        {
            displalyInfo.displayInfoMain(((Button)sender).Text + "按钮按下");
            var arr_step = Enum.GetNames(typeof(e_Step_Label));
            if (arr_step.Contains(((Button)sender).Text))
            {
                var e_step = (e_Step_Label)Enum.Parse(typeof(e_Step_Label), ((Button)sender).Text);
                var curPlate = GetPosPlateSelect();
                if (curPlate == e_platePro.双平台无)
                {
                    MessageBox.Show("请选择平台");
                    return;
                }
                else
                {
                    GlobalMotion.Step_Labeling(e_step, curPlate, e_MachineStatus.无控制);
                }
            }
            else
            {
                MessageBox.Show($"请注册{((Button)sender).Text }按钮功能");
            }
        }
        private void btn_StepCut_Click(object sender, EventArgs e)
        {
            displalyInfo.displayInfoMain(((Button)sender).Text + "按钮按下");
            var arr_step = Enum.GetNames(typeof(e_Step_Cut));
            if (arr_step.Contains(((Button)sender).Text))
            {
                var e_step = (e_Step_Cut)Enum.Parse(typeof(e_Step_Cut), ((Button)sender).Text);
                var curPlate = GetPosPlateSelect();
                if (curPlate == e_platePro.双平台无)
                {
                    MessageBox.Show("请选择平台");
                    return;
                }
                else
                {
                    GlobalMotion.Step_Cut(e_step, curPlate, e_MachineStatus.无控制);
                }
            }
            else
            {
                MessageBox.Show($"请注册{((Button)sender).Text }按钮功能");
            }
        }
        private void Task_Status()
        {
            try
            {
                while(!GlobalVar.isExit)
                {
                    Thread.Sleep(30);
                    var curPlate = e_platePro.双平台无;
                    this.Invoke(new Action(() =>
                    {
                        curPlate = GetPosPlateSelect();
                    }));
                  double LabelX =0.0;
                   double LabelR=0.0;
                    bool cut_air = false;
                    bool label_airUp = false;
                    bool label_airDown = false;
                    bool label_airAlarm = false;
                    double CutR = 0.0;
                    switch (curPlate)
                    {
                        case e_platePro.平台1:
                            LabelX = GlobalMotion.Card_1.AxisList[(int)e_card1_axis.贴标X1下].m_AxisSts.CurrPosi;
                            LabelR = GlobalMotion.Card_1.AxisList[(int)e_card1_axis.贴标R1下].m_AxisSts.CurrPosi;
                            CutR = GlobalMotion.Card_1.AxisList[(int)e_card1_axis.撕膜R1].m_AxisSts.CurrPosi;
                            cut_air = GlobalMotion.Output_CardEx2[(int)e_output_extCard2.撕膜气缸1];
                            label_airUp = GlobalMotion.Input_CardEx2[(int)e_input_extCard2.贴标升降气缸原点1];
                            label_airDown = GlobalMotion.Input_CardEx1[(int)e_input_extCard1.贴标气缸到位1];
                            label_airAlarm = GlobalMotion.Input_CardEx2[(int)e_input_extCard2.吸标靶面真空报警1];
                            break;
                        case e_platePro.平台2:
                            LabelX = GlobalMotion.Card_1.AxisList[(int)e_card1_axis.贴标X2上].m_AxisSts.CurrPosi;
                            LabelR = GlobalMotion.Card_1.AxisList[(int)e_card1_axis.贴标R2上].m_AxisSts.CurrPosi;
                            CutR = GlobalMotion.Card_1.AxisList[(int)e_card1_axis.撕膜R2].m_AxisSts.CurrPosi;
                            cut_air = GlobalMotion.Output_CardEx2[(int)e_output_extCard2.撕膜气缸2];
                            label_airUp = GlobalMotion.Input_CardEx2[(int)e_input_extCard2.贴标升降气缸原点2];
                            label_airDown = GlobalMotion.Input_CardEx1[(int)e_input_extCard1.贴标气缸到位2];
                            label_airAlarm = GlobalMotion.Input_CardEx2[(int)e_input_extCard2.吸标靶面真空报警2];
                            break;
                    }
                    var LabelY = GlobalMotion.Card_1.AxisList[(int)e_card1_axis.贴标Y轴].m_AxisSts.CurrPosi;
                    var LabelZ = GlobalMotion.Card_1.AxisList[(int)e_card1_axis.贴标Z轴].m_AxisSts.CurrPosi;

                    var CutX = GlobalMotion.Card_1.AxisList[(int)e_card1_axis.撕膜X].m_AxisSts.CurrPosi;
                    var CutY= GlobalMotion.Card_1.AxisList[(int)e_card1_axis.撕膜Y].m_AxisSts.CurrPosi;
                    var CutZ = GlobalMotion.Card_1.AxisList[(int)e_card1_axis.撕膜Z].m_AxisSts.CurrPosi;

                    this.Invoke(new Action(()=> {
                        tbx_LabelX.Text = LabelX.ToString("F03");
                        tbx_LabelY.Text = LabelY.ToString("F03");
                        tbx_LabelZ.Text = LabelZ.ToString("F03");
                        tbx_LabelR.Text = LabelR.ToString("F03");
                        tbx_CutX.Text = CutX.ToString("F03");
                        tbx_CutY.Text = CutY.ToString("F03");
                        tbx_CutZ.Text = CutZ.ToString("F03");
                        tbx_CutR.Text = CutR.ToString("F03");
                        rbn_cut_air.Checked = cut_air;

                        rbn_airAlarm.Checked = !label_airAlarm;
                        rbn_airUp.Checked = label_airUp;
                        rbn_airDown.Checked =label_airDown ;
                    }));

                }

            }catch(Exception ex)
            {
                displalyInfo.displayInfoMain("Task_Status" + ex.Message);
            }
        }
        public double vel = 0.1;
        private void tbr_vel_ValueChanged(object sender, EventArgs e)
        {
            lbl_vel.Text = tbr_vel.Value.ToString() + "%";
            vel = ((double)tbr_vel.Value) / (double)100;
        }

        private void tbr_vel_Scroll(object sender, EventArgs e)
        {
            lbl_vel.Text = tbr_vel.Value.ToString() + "%";
            vel = ((double)tbr_vel.Value) / (double)100;
        }

        private void cbx_LabelPos_SelectedIndexChanged(object sender, EventArgs e)
        {
            var curPlate = GetPosPlateSelect();
            var str_select = cbx_LabelPos.Text;
            var arrPos=Enum.GetNames(typeof(e_Pos));
            if(arrPos.Contains(str_select))
            {
                var curPos=(e_Pos)Enum.Parse(typeof(e_Pos), str_select);
                AbsPostion curLabelPos = new AbsPostion();
                switch (curPlate)
                {
                    case e_platePro.平台1:
                        curLabelPos = GlobalVar.motionConfig.Plate1_pos[(int)curPos];
                        break;
                    case e_platePro.平台2:
                        curLabelPos = GlobalVar.motionConfig.Plate2_pos[(int)curPos];
                        break;
                }
                nud_LabelX.Value =(decimal) curLabelPos.X;
                nud_LabelY.Value = (decimal)curLabelPos.Y;
                nud_LabelZ.Value = (decimal)curLabelPos.Z;
                nud_LabelR.Value = (decimal)curLabelPos.R;
            }
        }

        private void cbx_CutPos_SelectedIndexChanged(object sender, EventArgs e)
        {
            var curPlate = GetPosPlateSelect();
            var str_select = cbx_CutPos.Text;
            var arrPos = Enum.GetNames(typeof(e_PosCut));
            if (arrPos.Contains(str_select))
            {
                var curPos = (e_PosCut)Enum.Parse(typeof(e_PosCut), str_select);
                CutPostion curCutPos = new CutPostion();
                curCutPos = GlobalVar.motionConfig.Cut_pos[(int)curPos];
                nud_CutX.Value = (decimal)curCutPos.X;
                nud_CutY.Value = (decimal)curCutPos.Y;
                nud_CutZ.Value = (decimal)curCutPos.Z;
                if(curPlate==e_platePro.平台1)
                    nud_CutR.Value = (decimal)curCutPos.R1;
                else if (curPlate == e_platePro.平台2)
                    nud_CutR.Value = (decimal)curCutPos.R2;
            }
        }

        private void btn_SaveLabelPos_Click(object sender, EventArgs e)
        {
            var curPlate = GetPosPlateSelect();
            var str_select = cbx_LabelPos.Text;
            var arrPos = Enum.GetNames(typeof(e_Pos));
            if (arrPos.Contains(str_select))
            {
                var curPos = (e_Pos)Enum.Parse(typeof(e_Pos), str_select);
                switch (curPlate)
                {
                    case e_platePro.平台1:
                        {
                            AbsPostion curLabelPos = GlobalVar.motionConfig.Plate1_pos[(int)curPos];
                            curLabelPos.X = (double)nud_LabelX.Value;
                            curLabelPos.Y = (double)nud_LabelY.Value;
                            curLabelPos.Z = (double)nud_LabelZ.Value;
                            curLabelPos.R = (double)nud_LabelR.Value;
                            GlobalVar.motionConfig.Plate1_pos[(int)curPos] = curLabelPos;
                        }
                        break;
                    case e_platePro.平台2:
                        {
                            AbsPostion curLabelPos = GlobalVar.motionConfig.Plate2_pos[(int)curPos];
                            curLabelPos.X = (double)nud_LabelX.Value;
                            curLabelPos.Y = (double)nud_LabelY.Value;
                            curLabelPos.Z = (double)nud_LabelZ.Value;
                            curLabelPos.R = (double)nud_LabelR.Value;
                            GlobalVar.motionConfig.Plate2_pos[(int)curPos] = curLabelPos;
                           
                        }
                        break;
                }
                UpdateLabelPos(curPos, curPlate);
            }
        }

        private void btn_SaveCutPos_Click(object sender, EventArgs e)
        {
            var curPlate = GetPosPlateSelect();
            var str_select = cbx_CutPos.Text;
            var arrPos = Enum.GetNames(typeof(e_PosCut));
            if (arrPos.Contains(str_select))
            {
                var curPos = (e_PosCut)Enum.Parse(typeof(e_PosCut), str_select);
                CutPostion curCutPos = new CutPostion();
                curCutPos = GlobalVar.motionConfig.Cut_pos[(int)curPos];
                curCutPos.X=(double)nud_LabelX.Value;
                curCutPos.Y=(double) nud_LabelY.Value ;
                curCutPos.Z= (double)nud_LabelZ.Value;
                if (curPlate == e_platePro.平台1)
                    curCutPos.R1 = (double)nud_LabelR.Value ;
                else if (curPlate == e_platePro.平台2)
                    curCutPos.R2 = (double)nud_LabelR.Value;
               GlobalVar.motionConfig.Cut_pos[(int)curPos]= curCutPos;
                UpdateCutPos(curPos);
            }
        }
        private void rbn_PosPlate1_CheckedChanged(object sender, EventArgs e)
        {
            var curPlate = GetPosPlateSelect();
            if (curPlate == e_platePro.平台1)
            {
                btn_label_X负.Text = "X+";
                btn_label_X正.Text = "X-";
            }
            else if (curPlate == e_platePro.平台2)
            {
                btn_label_X负.Text = "X-";
                btn_label_X正.Text = "X+";
            }
        }
        #region  贴膜点动
        private void btn_Move_LableX_Click(object sender, EventArgs e)
        {
            var curPlate = GetPosPlateSelect();
            if (curPlate == e_platePro.平台1)
                GlobalMotion.Card_1.AxisList[(int)e_card1_axis.贴标X1下].PointMove((double)nud_LabelX.Value, vel, true);
            else if (curPlate == e_platePro.平台2)
                GlobalMotion.Card_1.AxisList[(int)e_card1_axis.贴标X2上].PointMove((double)nud_LabelX.Value, vel, true);
            displalyInfo.displayInfoMain("手动" + ((Button)sender).Text + "完成");
        }
        private void btn_Move_LableR_Click(object sender, EventArgs e)
        {
            var curPlate = GetPosPlateSelect();
            if (curPlate == e_platePro.平台1)
                GlobalMotion.Card_1.AxisList[(int)e_card1_axis.贴标R1下].PointMove((double)nud_LabelR.Value, vel, true);
            else if (curPlate == e_platePro.平台2)
                GlobalMotion.Card_1.AxisList[(int)e_card1_axis.贴标R2上].PointMove((double)nud_LabelR.Value, vel, true);
            displalyInfo.displayInfoMain("手动" + ((Button)sender).Text + "完成");
        }

        private void btn_Move_LableY_Click(object sender, EventArgs e)
        {
            GlobalMotion.Card_1.AxisList[(int)e_card1_axis.贴标Y轴].PointMove((double)nud_LabelY.Value, vel, true);
            displalyInfo.displayInfoMain("手动" + ((Button)sender).Text + "完成");
        }

        private void btn_Move_LableZ_Click(object sender, EventArgs e)
        {
            GlobalMotion.Card_1.AxisList[(int)e_card1_axis.贴标Z轴].PointMove((double)nud_LabelZ.Value, vel, true);
            displalyInfo.displayInfoMain("手动" + ((Button)sender).Text + "完成");
        }
        #endregion
        #region 撕膜点动
        private void btn_Move_CutR_Click(object sender, EventArgs e)
        {
            var curPlate = GetPosPlateSelect();
            if (curPlate == e_platePro.平台1)
                GlobalMotion.Card_1.AxisList[(int)e_card1_axis.撕膜R1].PointMove((double)nud_CutR.Value, vel, true);
            else if (curPlate == e_platePro.平台2)
                GlobalMotion.Card_1.AxisList[(int)e_card1_axis.撕膜R2].PointMove((double)nud_CutR.Value, vel, true);
        }

        private void btn_Move_CutX_Click(object sender, EventArgs e)
        {
                GlobalMotion.Card_1.AxisList[(int)e_card1_axis.撕膜X].PointMove((double)nud_CutX.Value, vel, true);
        }

        private void btn_Move_CutY_Click(object sender, EventArgs e)
        {
            GlobalMotion.Card_1.AxisList[(int)e_card1_axis.撕膜Y].PointMove((double)nud_CutY.Value, vel, true);
        }

        private void btn_Move_CutZ_Click(object sender, EventArgs e)
        {
            GlobalMotion.Card_1.AxisList[(int)e_card1_axis.撕膜Z].PointMove((double)nud_CutZ.Value, vel, true);
        }
        #endregion
        #region 贴标Jog按钮
        private void btn_label_R负_MouseDown(object sender, MouseEventArgs e)
        {
            var curPlate = GetPosPlateSelect();
            if (curPlate == e_platePro.平台1)
            {
                if (((Button)sender).Name.Contains("负"))
                    GlobalMotion.Card_1.AxisList[(int)e_card1_axis.贴标R1下].JogMove(MotionControl.e_moveDirection.negative, vel);
                else
                    GlobalMotion.Card_1.AxisList[(int)e_card1_axis.贴标R1下].JogMove(MotionControl.e_moveDirection.positive, vel);
            }
            else if (curPlate == e_platePro.平台2)
            {
                if (((Button)sender).Name.Contains("负"))
                    GlobalMotion.Card_1.AxisList[(int)e_card1_axis.贴标R2上].JogMove(MotionControl.e_moveDirection.negative, vel);
                else
                    GlobalMotion.Card_1.AxisList[(int)e_card1_axis.贴标R2上].JogMove(MotionControl.e_moveDirection.positive, vel);
            }
        }

        private void btn_label_R负_MouseUp(object sender, MouseEventArgs e)
        {
            displalyInfo.displayInfoMain("手动" + ((Button)sender).Text + "完成");
            GlobalMotion.Card_1.AxisList[(int)e_card1_axis.贴标R1下].AxisStop();
            GlobalMotion.Card_1.AxisList[(int)e_card1_axis.贴标R2上].AxisStop();
        }

        private void btn_label_X负_MouseDown(object sender, MouseEventArgs e)
        {
            var curPlate = GetPosPlateSelect();
            if (curPlate == e_platePro.平台1)
            {
                if (((Button)sender).Text.Contains("-"))
                    GlobalMotion.Card_1.AxisList[(int)e_card1_axis.贴标X1下].JogMove(MotionControl.e_moveDirection.negative, vel);
                else
                    GlobalMotion.Card_1.AxisList[(int)e_card1_axis.贴标X1下].JogMove(MotionControl.e_moveDirection.positive, vel);
            }
            else if (curPlate == e_platePro.平台2)
            {
                if (((Button)sender).Text.Contains("-"))
                    GlobalMotion.Card_1.AxisList[(int)e_card1_axis.贴标X2上].JogMove(MotionControl.e_moveDirection.negative, vel);
                else
                    GlobalMotion.Card_1.AxisList[(int)e_card1_axis.贴标X2上].JogMove(MotionControl.e_moveDirection.positive, vel);
            }
        }

        private void btn_label_X负_MouseUp(object sender, MouseEventArgs e)
        {
            displalyInfo.displayInfoMain("手动" + ((Button)sender).Text + "完成");
            GlobalMotion.Card_1.AxisList[(int)e_card1_axis.贴标X2上].AxisStop();
            GlobalMotion.Card_1.AxisList[(int)e_card1_axis.贴标X1下].AxisStop();
        }

        private void btn_label_Y负_MouseDown(object sender, MouseEventArgs e)
        {
                if (((Button)sender).Text.Contains("-"))
                    GlobalMotion.Card_1.AxisList[(int)e_card1_axis.贴标Y轴].JogMove(MotionControl.e_moveDirection.negative, vel);
                else
                    GlobalMotion.Card_1.AxisList[(int)e_card1_axis.贴标Y轴].JogMove(MotionControl.e_moveDirection.positive, vel);
        }

        private void btn_label_Y负_MouseUp(object sender, MouseEventArgs e)
        {
            displalyInfo.displayInfoMain("手动" + ((Button)sender).Text + "完成");
            GlobalMotion.Card_1.AxisList[(int)e_card1_axis.贴标Y轴].AxisStop();
         
        }

        private void btn_label_Z负_MouseUp(object sender, MouseEventArgs e)
        {
            displalyInfo.displayInfoMain("手动" + ((Button)sender).Text + "完成");
            GlobalMotion.Card_1.AxisList[(int)e_card1_axis.贴标Z轴].AxisStop();
        }

        private void btn_label_Z负_MouseDown(object sender, MouseEventArgs e)
        {
            if (((Button)sender).Text.Contains("-"))
                GlobalMotion.Card_1.AxisList[(int)e_card1_axis.贴标Z轴].JogMove(MotionControl.e_moveDirection.negative, vel);
            else
                GlobalMotion.Card_1.AxisList[(int)e_card1_axis.贴标Z轴].JogMove(MotionControl.e_moveDirection.positive, vel);
        }
        #endregion
        #region 撕膜Jog按钮
        private void btn_cut_R负_MouseDown(object sender, MouseEventArgs e)
        {
            var curPlate = GetPosPlateSelect();
            if (curPlate == e_platePro.平台1)
            {
                if (((Button)sender).Name.Contains("负"))
                    GlobalMotion.Card_1.AxisList[(int)e_card1_axis.撕膜R1].JogMove(MotionControl.e_moveDirection.negative, vel);
                else
                    GlobalMotion.Card_1.AxisList[(int)e_card1_axis.撕膜R1].JogMove(MotionControl.e_moveDirection.positive, vel);
            }
            else if (curPlate == e_platePro.平台2)
            {
                if (((Button)sender).Name.Contains("负"))
                    GlobalMotion.Card_1.AxisList[(int)e_card1_axis.撕膜R2].JogMove(MotionControl.e_moveDirection.negative, vel);
                else
                    GlobalMotion.Card_1.AxisList[(int)e_card1_axis.撕膜R2].JogMove(MotionControl.e_moveDirection.positive, vel);
            }
        }

        private void btn_cut_R负_MouseUp(object sender, MouseEventArgs e)
        {
            displalyInfo.displayInfoMain("手动" + ((Button)sender).Text + "完成");
            GlobalMotion.Card_1.AxisList[(int)e_card1_axis.撕膜R1].AxisStop();
            GlobalMotion.Card_1.AxisList[(int)e_card1_axis.撕膜R2].AxisStop();
    }

        private void btn_Cut_Y负_MouseDown(object sender, MouseEventArgs e)
        {
            if (((Button)sender).Text.Contains("-"))
                GlobalMotion.Card_1.AxisList[(int)e_card1_axis.撕膜Y].JogMove(MotionControl.e_moveDirection.negative, vel);
            else
                GlobalMotion.Card_1.AxisList[(int)e_card1_axis.撕膜Y].JogMove(MotionControl.e_moveDirection.positive, vel);
        }

        private void btn_Cut_Y负_MouseUp(object sender, MouseEventArgs e)
        {
            displalyInfo.displayInfoMain("手动" + ((Button)sender).Text + "完成");
            GlobalMotion.Card_1.AxisList[(int)e_card1_axis.撕膜Y].AxisStop();
        }

        private void btn_Cut_X负_MouseDown(object sender, MouseEventArgs e)
        {
            if (((Button)sender).Text.Contains("-"))
                GlobalMotion.Card_1.AxisList[(int)e_card1_axis.撕膜X].JogMove(MotionControl.e_moveDirection.negative, vel);
            else
                GlobalMotion.Card_1.AxisList[(int)e_card1_axis.撕膜X].JogMove(MotionControl.e_moveDirection.positive, vel);
        }

        private void btn_Cut_X负_MouseUp(object sender, MouseEventArgs e)
        {
            displalyInfo.displayInfoMain("手动" + ((Button)sender).Text + "完成");
            GlobalMotion.Card_1.AxisList[(int)e_card1_axis.撕膜X].AxisStop();
        }

        private void btn_Cut_Z负_MouseDown(object sender, MouseEventArgs e)
        {
            if (((Button)sender).Text.Contains("-"))
                GlobalMotion.Card_1.AxisList[(int)e_card1_axis.撕膜Z].JogMove(MotionControl.e_moveDirection.negative, vel);
            else
                GlobalMotion.Card_1.AxisList[(int)e_card1_axis.撕膜Z].JogMove(MotionControl.e_moveDirection.positive, vel);
        }

        private void btn_Cut_Z负_MouseUp(object sender, MouseEventArgs e)
        {
            displalyInfo.displayInfoMain("手动" + ((Button)sender).Text + "完成");
            GlobalMotion.Card_1.AxisList[(int)e_card1_axis.撕膜Z].AxisStop();
        }
        #endregion

        private void btn_selectOCRfile_Click(object sender, EventArgs e)
        {
            try
            {
                OpenFileDialog ofd = new OpenFileDialog();
                ofd.Filter = "All File(*.*)|*.*";
                ofd.Title = "选择打印模板文件";
                ofd.InitialDirectory = Application.StartupPath;
                if (ofd.ShowDialog() == DialogResult.OK)
                {
                    HOperatorSet.ReadImage(out HObject temp, ofd.FileName);
                    visionProc.srcObject_scan = temp;
                    GlobalVar.imageDisplay1(visionProc.srcObject_scan);
                }
            }
            catch (Exception ex)
            {
                displalyInfo.displayInfoMain($"{((Button)sender).Text}-[error] {ex.Message}");
            }
        }

        private void btn_Trans_Click(object sender, EventArgs e)
        {
          
        }
        #region 绘制区域
        //private void hswc_Scan_Load(object sender, EventArgs e)
        //{
        //    hswc_Scan.Parent.MouseWheel += my_MouseWheel_2;
        //    hswc_Scan.HMouseMove += new HMouseEventHandler(Image2_MouseMove);
        //    hswc_Scan.HMouseDown += new HMouseEventHandler(Image2_MouseDown);
        //    hswc_Scan.HMouseUp += new HMouseEventHandler(Image2_MouseUp);
        //    GlobalVar.hwindow_cam_2_hwin = hswc_Scan.HalconWindow;
        //    hswc_Scan.HalconWindow.SetDraw("margin");
        //    hswc_Scan.SetFullImagePart();
        //}
        //private void my_MouseWheel_2(object sender, MouseEventArgs e)
        //{
        //    try
        //    {
        //        Point pt = hswc_Scan.Location;
        //        int leftBorder = hswc_Scan.Location.X;
        //        int rightBorder = hswc_Scan.Location.X + hswc_Scan.Size.Width;
        //        int topBorder = hswc_Scan.Location.Y;
        //        int bottomBorder = hswc_Scan.Location.Y + hswc_Scan.Size.Height;

        //        if (e.X > leftBorder && e.X < rightBorder && e.Y > topBorder && e.Y < bottomBorder)
        //        {
        //            MouseEventArgs newe = new MouseEventArgs(e.Button, e.Clicks, e.X - pt.X, e.Y - pt.Y, e.Delta);
        //            hswc_Scan.HSmartWindowControl_MouseWheel(sender, newe);
        //        }
        //    }
        //    catch (System.Exception ex)
        //    {
        //        displalyInfo.displayInfoMain("鼠标滚轮操作异常 :" + ex.Message);

        //    }

        //}
        //private void Image2_MouseMove(object sender, HMouseEventArgs e)
        //{

        //    if (((HSmartWindowControl)sender).Name == "hswc_Scan")
        //    {
             
        //        if (e.Button.ToString() == "Left" && e.Y > 0 && e.X > 0)
        //        {
        //            HOperatorSet.GetImageSize(visionProc.srcObject_scan, out HTuple imgWidth, out HTuple imgHeight);
        //            if (e.X <= imgWidth.D && e.Y <= imgHeight.D)
        //            {
        //                HOperatorSet.GetGrayval(visionProc.srcObject_scan, e.Y, e.X, out HTuple grayval);
        //                tbx_grayVal.Text = grayval.I.ToString();
        //            }
        //        }
        //        if (isDown1 && e.Button.ToString() == "Left" && visionProc.isReduce)
        //        {
        //            point_move2 = new PointF((float)e.X, (float)e.Y);
        //            HObject curRegion;
        //            HOperatorSet.GenCircle(out curRegion, point_move2.Y, point_move2.X, visionProc.reduce_Radius);
        //            if (!MaskRegion2.IsInitialized())
        //                MaskRegion2 = curRegion;
        //            else
        //            {
        //                HObject conObj;
        //                HOperatorSet.ConcatObj(MaskRegion2, curRegion, out conObj);
        //                MaskRegion2 = conObj;
        //            }
        //            HOperatorSet.Difference(visionProc.ROI2.ROI_Template, MaskRegion2, out HObject MaskResult);
        //            visionProc.ROI2.ROI_Template = MaskResult;
        //            ImageDisplay_2_objSimple(visionProc.ROI2.ROI_Template, "blue");
        //        }
        //    }

        //}
        //public void ImageDisplay_2_objSimple(HObject drawObject, string color)
        //{
        //    try
        //    {
        //            hswc_Scan.Invoke(new MethodInvoker(() =>
        //            {
        //                hswc_Scan.HalconWindow.ClearWindow();
        //                hswc_Scan.HalconWindow.DispObj(visionProc.srcObject_scan);
        //                hswc_Scan.HalconWindow.SetColor(color);
        //                hswc_Scan.HalconWindow.SetDraw("margin");
        //                hswc_Scan.HalconWindow.DispObj(drawObject);
        //            }));
        //    }
        //    catch (Exception ex)
        //    {
        //        displalyInfo.displayInfoMain("图案相机检测显示异常:" + ex.Message);

        //    }
        //}
        PointF point_move2;
        /// <summary>
        /// 涂抹区域
        /// </summary>
        HObject MaskRegion2 = new HObject();
        //public void DrawRoiRegion2()
        //{
        //    visionProc.DrawRoiRegion2(hswc_Scan);
        //}
        //public void ClearRoiRegion2()
        //{
        //    visionProc.ClearROIRegion2();
        //}
        //public void ImageDisplay_2_obj(HObject measureImage, string color)
        //{
        //    if (measureImage == null)
        //        measureImage = new HObject();
        //    hswc_Scan.BeginInvoke(new MethodInvoker(() =>
        //    {
        //        try
        //        {
        //            hswc_Scan.HalconWindow.SetDraw("margin");
        //            hswc_Scan.HalconWindow.SetColor(color);
        //            measureImage.DispObj(hswc_Scan.HalconWindow);
        //            hswc_Scan.SetFullImagePart();
        //        }
        //        catch (Exception ex)
        //        {
        //            displalyInfo.displayInfoMain("图案相机显示异常:" + ex.Message);
        //        }
        //    }));
        //}
        //public void ImageDisplay_2(HObject measureImage)
        //{
        //    try
        //    {
        //        hswc_Scan.BeginInvoke(new MethodInvoker(() =>
        //        {

        //            hswc_Scan.HalconWindow.ClearWindow();
        //            measureImage.DispObj(hswc_Scan.HalconWindow);
        //            hswc_Scan.SetFullImagePart();
        //        }));
        //    }
        //    catch (Exception ex)
        //    {
        //        displalyInfo.displayInfoMain("ImageDisplay_2:" + ex.Message);

        //    }
        //}
        //private void Image2_MouseUp(object sender, HMouseEventArgs e)
        //{
        //    if (isDown1)
        //    {
        //        isDown1 = false;
        //        hswc_Scan.HMoveContent = true;
        //    }
        //}
        //bool isDown1 = false;
        //private void Image2_MouseDown(object sender, HMouseEventArgs e)
        //{
        //    if (!isDown1 && e.Button.ToString() == "Left" && visionProc.isReduce)
        //    {
        //        hswc_Scan.HMoveContent = false;
        //        isDown1 = true;
        //    }
        //}
        #endregion

        #region 绘制区域
        //private void hswc_Check_Load(object sender, EventArgs e)
        //{
        //    hswc_Check.Parent.MouseWheel += my_MouseWheel_3;
        //    hswc_Check.HMouseMove += new HMouseEventHandler(Image3_MouseMove);
        //    hswc_Check.HMouseDown += new HMouseEventHandler(Image3_MouseDown);
        //    hswc_Check.HMouseUp += new HMouseEventHandler(Image3_MouseUp);

        //    hswc_Check.HalconWindow.SetDraw("margin");
        //    hswc_Check.SetFullImagePart();
        //}
        //private void my_MouseWheel_3(object sender, MouseEventArgs e)
        //{
        //    try
        //    {
        //        Point pt = hswc_Check.Location;
        //        int leftBorder = hswc_Check.Location.X;
        //        int rightBorder = hswc_Check.Location.X + hswc_Check.Size.Width;
        //        int topBorder = hswc_Check.Location.Y;
        //        int bottomBorder = hswc_Check.Location.Y + hswc_Check.Size.Height;

        //        if (e.X > leftBorder && e.X < rightBorder && e.Y > topBorder && e.Y < bottomBorder)
        //        {
        //            MouseEventArgs newe = new MouseEventArgs(e.Button, e.Clicks, e.X - pt.X, e.Y - pt.Y, e.Delta);
        //            hswc_Check.HSmartWindowControl_MouseWheel(sender, newe);
        //        }
        //    }
        //    catch (System.Exception ex)
        //    {
        //        displalyInfo.displayInfoMain("鼠标滚轮操作异常 :" + ex.Message);

        //    }

        //}
        //private void Image3_MouseMove(object sender, HMouseEventArgs e)
        //{
        //    try
        //    {
        //        if (((HSmartWindowControl)sender).Name == "hswc_Check")
        //        {

        //            if (e.Button.ToString() == "Left" && e.Y > 0 && e.X > 0)
        //            {
        //                HOperatorSet.GetImageSize(visionProc.srcObject_ckeck, out HTuple imgWidth, out HTuple imgHeight);
        //                if (e.X <= imgWidth.D && e.Y <= imgHeight.D)
        //                {
        //                    HOperatorSet.GetGrayval(visionProc.srcObject_ckeck, e.Y, e.X, out HTuple grayval);
        //                    tbx_grayVal3.Text = grayval.I.ToString();
        //                }
        //            }
        //            if (isDown3 && e.Button.ToString() == "Left" && visionProc.isReduce)
        //            {
        //                point_move3 = new PointF((float)e.X, (float)e.Y);
        //                HObject curRegion;
        //                HOperatorSet.GenCircle(out curRegion, point_move3.Y, point_move3.X, visionProc.reduce_Radius);
        //                if (!MaskRegion3.IsInitialized())
        //                    MaskRegion3 = curRegion;
        //                else
        //                {
        //                    HObject conObj;
        //                    HOperatorSet.ConcatObj(MaskRegion3, curRegion, out conObj);
        //                    MaskRegion3 = conObj;
        //                }
        //                HOperatorSet.Difference(visionProc.ROI3.ROI_Template, MaskRegion3, out HObject MaskResult);
        //                visionProc.ROI3.ROI_Template = MaskResult;
        //                ImageDisplay_3_objSimple(visionProc.ROI3.ROI_Template, "blue");
        //            }
        //        }
        //    }
        //    catch (Exception)
        //    {

        //    }
            

        //}
        //public void ImageDisplay_3_objSimple(HObject drawObject, string color)
        //{
        //    try
        //    {
        //        hswc_Check.Invoke(new MethodInvoker(() =>
        //        {
        //            hswc_Check.HalconWindow.ClearWindow();
        //            hswc_Check.HalconWindow.DispObj(visionProc.srcObject_ckeck);
        //            hswc_Check.HalconWindow.SetColor(color);
        //            hswc_Check.HalconWindow.SetDraw("margin");
        //            hswc_Check.HalconWindow.DispObj(drawObject);
        //        }));
        //    }
        //    catch (Exception ex)
        //    {
        //        displalyInfo.displayInfoMain("检测相机检测显示异常:" + ex.Message);

        //    }
        //}
        PointF point_move3;
        /// <summary>
        /// 涂抹区域
        /// </summary>
        HObject MaskRegion3 = new HObject();
        //public void DrawRoiRegion3()
        //{
        //    visionProc.DrawRoiRegion3(hswc_Check);
        //}
        //public void ClearRoiRegion3()
        //{
        //    visionProc.ClearROIRegion3();
        //}
        //public void ImageDisplay_3_obj(HObject measureImage, string color)
        //{
        //    if (measureImage == null)
        //        measureImage = new HObject();
        //    hswc_Check.Invoke(new MethodInvoker(() =>
        //    {
        //        try
        //        {
        //            hswc_Check.HalconWindow.SetDraw("margin");
        //            hswc_Check.HalconWindow.SetColor(color);
        //            measureImage.DispObj(hswc_Check.HalconWindow);
        //            hswc_Check.SetFullImagePart();
        //        }
        //        catch (Exception ex)
        //        {
        //            displalyInfo.displayInfoMain("检测相机显示异常:" + ex.Message);
        //        }
        //    }));
        //}
        //public void ImageDisplay_3(HObject measureImage)
        //{
        //    try
        //    {
        //        hswc_Check.BeginInvoke(new MethodInvoker(() =>
        //        {

        //            hswc_Check.HalconWindow.ClearWindow();
        //            measureImage.DispObj(hswc_Check.HalconWindow);
        //            hswc_Check.SetFullImagePart();
        //        }));
        //    }
        //    catch (Exception ex)
        //    {
        //        displalyInfo.displayInfoMain("ImageDisplay_3:" + ex.Message);

        //    }
        //}
        //private void Image3_MouseUp(object sender, HMouseEventArgs e)
        //{
        //    if (isDown3)
        //    {
        //        isDown3 = false;
        //        hswc_Check.HMoveContent = true;
        //    }
        //}
        //bool isDown3 = false;
        //private void Image3_MouseDown(object sender, HMouseEventArgs e)
        //{
        //    if (!isDown3 && e.Button.ToString() == "Left" && visionProc.isReduce)
        //    {
        //        hswc_Check.HMoveContent = false;
        //        isDown3 = true;
        //    }
        //}
        #endregion

        private void btn_cut_NGZHeight_Click(object sender, EventArgs e)
        {
            GlobalMotion.Card_1.AxisList[(int)e_card1_axis.撕膜Z].PointMove((double)nud_cut_NGZHeight.Value, true);
        }

        private void btn_cut_NGZLow_Click(object sender, EventArgs e)
        {
            GlobalMotion.Card_1.AxisList[(int)e_card1_axis.撕膜Z].PointMove((double)nud_cut_NGZLow.Value, true);
        }

        private void nud_cut_EndX_ValueChanged(object sender, EventArgs e)
        {

        }

        private void nud_cut_mediumX_ValueChanged(object sender, EventArgs e)
        {

        }

        private void nud_cut_ClampX_ValueChanged(object sender, EventArgs e)
        {

        }

        private void nud_cut_ProX_ValueChanged(object sender, EventArgs e)
        {

        }

        private void nud_cut_WaitX_ValueChanged(object sender, EventArgs e)
        {

        }

        private void nud_cut_WaitY_ValueChanged(object sender, EventArgs e)
        {

        }

        private void nud_cut_ProY_ValueChanged(object sender, EventArgs e)
        {

        }

        private void nud_cut_WaitZ_ValueChanged(object sender, EventArgs e)
        {

        }

        private void nud_cut_ProZ_ValueChanged(object sender, EventArgs e)
        {

        }

        private void nud_cut_ClampY_ValueChanged(object sender, EventArgs e)
        {

        }

        private void nud_cut_ClampZ_ValueChanged(object sender, EventArgs e)
        {

        }

        private void nud_cut_mediumZ_ValueChanged(object sender, EventArgs e)
        {

        }

        private void nud_cut_mediumR1_ValueChanged(object sender, EventArgs e)
        {

        }

        private void nud_cut_ClampR1_ValueChanged(object sender, EventArgs e)
        {

        }

        private void nud_cut_ProR1_ValueChanged(object sender, EventArgs e)
        {

        }

        private void nud_cut_WaitR1_ValueChanged(object sender, EventArgs e)
        {

        }

        private void nud_cut_WaitR2_ValueChanged(object sender, EventArgs e)
        {

        }

        private void nud_cut_ProR2_ValueChanged(object sender, EventArgs e)
        {

        }

        private void nud_cut_ClampR2_ValueChanged(object sender, EventArgs e)
        {

        }

        private void nud_cut_mediumR2_ValueChanged(object sender, EventArgs e)
        {

        }

        private void nud_cut_EndR2_ValueChanged(object sender, EventArgs e)
        {

        }

        private void nud_cut_NGR1_ValueChanged(object sender, EventArgs e)
        {

        }

        private void nud_cut_EndR1_ValueChanged(object sender, EventArgs e)
        {

        }

        private void nud_cut_EndZ_ValueChanged(object sender, EventArgs e)
        {

        }

        private void nud_cut_NGZ_ValueChanged(object sender, EventArgs e)
        {

        }

        private void nud_cut_NGY_ValueChanged(object sender, EventArgs e)
        {

        }

        private void nud_cut_EndY_ValueChanged(object sender, EventArgs e)
        {

        }

        private void nud_cut_mediumY_ValueChanged(object sender, EventArgs e)
        {

        }

        private void cbo_type_selectType_SelectedIndexChanged_1(object sender, EventArgs e)
        {
            if (cbo_type_selectType.SelectedIndex > -1)
            {
                var strSelect = cbo_type_selectType.Text;
                var tList = GlobalVar.tv_list.Where(a => a.type == strSelect).ToList();
                if (tList.Count > 0)
                {
                    if (((ComboBox)sender).Name == "cbo_type_selectType")
                    {
                        var strVersion11 = cbo_selectVersion.Text;
                        var arrVer = GlobalVar.tv_list.Where(a => a.type == cbo_type_selectType.Text).Select(a => a.Version).Distinct().ToArray();
                        cbo_selectVersion.Items.Clear();
                        cbo_selectVersion.Items.AddRange(arrVer);
                        if (arrVer.Contains(strVersion11))
                            cbo_selectVersion.Text = strVersion11;
                        else
                            cbo_selectVersion.Text = "";
                    }
                }
            }
        }
        //private int FreshVersionType(string typeVersion)
        //{
        //    try
        //    {
        //        typeVersion = GlobalVar.closeSave.CurrentTypeName;

        //        this.cbo_type_selectType.SelectedIndexChanged -= new System.EventHandler(this.cbo_selectVersion_SelectedIndexChanged);
        //        cbo_selectVersion.Items.Clear();
        //        cbo_type_selectType.Items.Clear();
        //        if (GlobalVar.tv_list.Count > 0)
        //        {
        //            cbo_type_selectType.Items.AddRange(GlobalVar.tv_list.Select(A => A.type).Distinct().ToArray());
        //            if (typeVersion.Contains(GlobalVar.char_VersionSpilt))
        //            {
        //                var arr = typeVersion.Split(GlobalVar.char_VersionSpilt);
        //                var arrVersion = GlobalVar.tv_list.Where(A => A.type == arr[0]).Select(A => A.Version).Distinct().ToArray();
        //                cbo_selectVersion.Items.AddRange(arrVersion);
        //                cbo_type_selectType.Text = arr[0];
        //                cbo_selectVersion.Text = arr[1];
        //            }
        //        }
        //        this.cbo_type_selectType.SelectedIndexChanged += new System.EventHandler(this.cbo_selectVersion_SelectedIndexChanged);


        //    }
        //    catch (Exception ex)
        //    {
        //        return -1;
        //    }

        //    return 1;
        //}
        private void btn_changeModel_Click(object sender, EventArgs e)
        {
            var curType = cbo_type_selectType.Text.Trim();
            var curVersion = cbo_selectVersion.Text.Trim();
            if (string.IsNullOrEmpty(curType) || string.IsNullOrEmpty(curVersion))
            {
                return;
            }
            var curlist = GlobalVar.tv_list.Where(a => a.type == curType && a.Version == curVersion).ToList();
            if (curlist.Count < 1)
            {
                MessageBox.Show("产品名称 产品型号 不存在");
                return;
            }
            if (curlist[0].GetTypeVersion() == GlobalVar.closeSave.CurrentTypeName)
            {
                MessageBox.Show("产品名称 产品型号 不存在");
                return;
            }
            if (GlobalVar.isAutoRun)
            {
                MessageBox.Show("机器自动状态下不能切换产品");
                return;
            }
            try
            {
                PageVersionConfirm confirm = new PageVersionConfirm(curlist[0].GetTypeVersion());
                confirm.ShowDialog();
            }
            catch (Exception ex)
            {
                displalyInfo.displayInfoMain(ex.StackTrace);
            }
        }

        //private void button4_Click(object sender, EventArgs e)
        //{
        //    FolderBrowserDialog ofg = new FolderBrowserDialog();
        //    ofg.Description = ((Button)sender).Text;
        //    ofg.SelectedPath = Environment.CurrentDirectory;
        //    var res = ofg.ShowDialog();
        //    if (res == DialogResult.OK)
        //    {
        //        string paths = ofg.SelectedPath;
        //        rbt_dir_OKDraw.Text = paths;
        //    }
        //}

        //private void button2_Click(object sender, EventArgs e)
        //{
        //    FolderBrowserDialog ofg = new FolderBrowserDialog();
        //    ofg.Description = ((Button)sender).Text;
        //    ofg.SelectedPath = Environment.CurrentDirectory;
        //    var res = ofg.ShowDialog();
        //    if (res == DialogResult.OK)
        //    {
        //        string paths = ofg.SelectedPath;
        //        rbt_dir_NGDraw.Text = paths;
        //    }
        //}

        //private void button5_Click(object sender, EventArgs e)
        //{
        //    FolderBrowserDialog ofg = new FolderBrowserDialog();
        //    ofg.Description = ((Button)sender).Text;
        //    ofg.SelectedPath = Environment.CurrentDirectory;
        //    var res = ofg.ShowDialog();
        //    if (res == DialogResult.OK)
        //    {
        //        string paths = ofg.SelectedPath;
        //        rbt_dir_OKCheck.Text = paths;
        //    }
        //}

        //private void button6_Click(object sender, EventArgs e)
        //{
        //    FolderBrowserDialog ofg = new FolderBrowserDialog();
        //    ofg.Description = ((Button)sender).Text;
        //    ofg.SelectedPath = Environment.CurrentDirectory;
        //    var res = ofg.ShowDialog();
        //    if (res == DialogResult.OK)
        //    {
        //        string paths = ofg.SelectedPath;
        //        rbt_dir_NGCheck.Text = paths;
        //    }
        //}

        private void groupBox24_Enter(object sender, EventArgs e)
        {

        }

        private void button7_Click(object sender, EventArgs e)
        {
            SaveFileDialog ofd = new SaveFileDialog();
            ofd.Filter = "All File(*.*)|*.*";
            ofd.Title = "选择打印模板文件";
            //ofd.InitialDirectory = Application.StartupPath;
            if (ofd.ShowDialog() == DialogResult.OK)
            {
                string selectName = ofd.FileName;
                try
                {
                    SerializeHelper.serializeFile($"撕膜_{selectName}.tfp", GlobalVar.motionConfig.Cut_pos, GlobalVar.closeSave.CurrentTypeName);
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);
                }
            }
        }

        private void button8_Click(object sender, EventArgs e)
        {
            OpenFileDialog ofd = new OpenFileDialog();
            ofd.Filter = "All File(*.*)|*.*";
            ofd.Title = "选择打印模板文件";
            //ofd.InitialDirectory = Application.StartupPath;
            if (ofd.ShowDialog() == DialogResult.OK)
            {
                string selectName = ofd.FileName;
                try
                {
                    var motionTemp = (List<CutPostion>)SerializeHelper.DeserializeFile<List<CutPostion>>($"{selectName}", "撕膜参数");
                    GlobalVar.motionConfig.Cut_pos = motionTemp;
                    UpdataCutPos();
                    MessageBox.Show("撕膜参数导入成功！");
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);
                }
            }
        }

        private void button9_Click(object sender, EventArgs e)
        {
            OpenFileDialog ofd = new OpenFileDialog();
            ofd.Filter = "All File(*.*)|*.*";
            ofd.Title = "选择打印模板文件";
            //ofd.InitialDirectory = Application.StartupPath;
            if (ofd.ShowDialog() == DialogResult.OK)
            {
                string selectName = ofd.FileName;
                try
                {
                    var motionTemp = (List<AbsPostion>)SerializeHelper.DeserializeFile<List<AbsPostion>>($"{selectName}", "贴膜参数");
                    GlobalVar.motionConfig.Plate1_pos = motionTemp;
                    rbn_plate1.Checked = true;
                    MessageBox.Show("贴膜参数导入成功！");
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);
                }
            }
        }

        private void button13_Click(object sender, EventArgs e)
        {
            SaveFileDialog ofd = new SaveFileDialog();
            ofd.Filter = "All File(*.*)|*.*";
            ofd.Title = "选择打印模板文件";
            //ofd.InitialDirectory = Application.StartupPath;
            if (ofd.ShowDialog() == DialogResult.OK)
            {
                string selectName = ofd.FileName;
                try
                {
                    SerializeHelper.serializeFile($"贴膜1_{selectName}.tfp", GlobalVar.motionConfig.Plate1_pos, GlobalVar.closeSave.CurrentTypeName);
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);
                }
            }
        }

        private void button14_Click(object sender, EventArgs e)
        {
            SaveFileDialog ofd = new SaveFileDialog();
            ofd.Filter = "All File(*.*)|*.*";
            ofd.Title = "选择打印模板文件";
            //ofd.InitialDirectory = Application.StartupPath;
            if (ofd.ShowDialog() == DialogResult.OK)
            {
                string selectName = ofd.FileName;
                try
                {
                    SerializeHelper.serializeFile($"贴膜2_{selectName}.tfp", GlobalVar.motionConfig.Plate2_pos, GlobalVar.closeSave.CurrentTypeName);
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);
                }
            }
        }

        private void button16_Click(object sender, EventArgs e)
        {
            SaveFileDialog ofd = new SaveFileDialog();
            ofd.Filter = "All File(*.*)|*.*";
            ofd.Title = "选择打印模板文件";
            //ofd.InitialDirectory = Application.StartupPath;
            if (ofd.ShowDialog() == DialogResult.OK)
            {
                string selectName = ofd.FileName;
                try
                {
                    SerializeHelper.serializeFile($"{selectName}.tfp", GlobalVar.motionConfig, GlobalVar.closeSave.CurrentTypeName);
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);
                }
            }
        }

        //private void button19_Click(object sender, EventArgs e)
        //{
        //    try
        //    {
        //        GlobalVar.IsPosBeforeLabel = true;
        //        GlobalVar.userConfig.IsCheckCutResult = true;
        //        GlobalVar.userConfig.IsPosAfterLabel = false;
        //        if (rbn_m_Plate1.Checked)
        //        {
        //            visionProc.visionProcCam(visionProc.srcObject_ckeck, e_CameraPlate.检测相机平台1);
        //        }
        //        else
        //        {
        //            visionProc.visionProcCam(visionProc.srcObject_ckeck, e_CameraPlate.检测相机平台2);
        //        }

        //        GlobalVar.IsPosBeforeLabel = false;
        //        GlobalVar.userConfig.IsCheckCutResult = false;
        //        textBox1.Text = visionProc.AllArea;
        //    }
        //    catch (Exception ex)
        //    {
        //        MessageBox.Show(ex.Message);
        //    }
            
        //}

        //private void btn_cameraTest(object sender, EventArgs e)
        //{
        //    var nRegionSelect = cbx_c_RegionSelect.Text;
        //    if (!string.IsNullOrEmpty(nRegionSelect) && cbx_c_RegionSelect.Items.IndexOf(nRegionSelect) > -1)
        //    {
        //        var IndexSelect = cbx_c_RegionSelect.Items.IndexOf(nRegionSelect);
        //        var arrStr = Enum.GetNames(typeof(e_RegionCheck));
        //        var e_Region = (e_RegionCheck)Enum.Parse(typeof(e_RegionCheck), arrStr[IndexSelect]);
        //        if (rbn_m_Plate1.Checked)
        //        {
        //            if (IndexSelect > 1)
        //            {
        //                GlobalVar.imageDisplay3_obj(visionProc.ROI_M_List1[IndexSelect], "green");
        //                var res = visionProc.GetMeasures(e_CameraPlate.检测相机平台1, Get_Measure(), e_Region);
        //                var n = res == null ? 0 : res.Count;
        //                displalyInfo.displayInfoMain($"该区域有{n}匹配对" + (n > 0 ? string.Join(",", res) : 0.ToString()));
        //            }
        //            else
        //            {
        //                HOperatorSet.ReduceDomain(visionProc.srcObject_ckeck, visionProc.ROI_M_List1[(int)e_RegionCheck.切图区域], out HObject cutObj);
        //                HOperatorSet.Threshold(cutObj, out HObject threadObj, (int)nud_m_grayMin.Value, (int)nud_m_grayMax.Value);
        //                HOperatorSet.Connection(threadObj, out threadObj);
        //                HOperatorSet.FillUp(threadObj, out threadObj);
        //                HOperatorSet.SelectShapeStd(threadObj, out threadObj, "max_area", 70);
        //                //visionProc.GetCutResult(visionProc.srcObject_ckeck, visionProc.ROI_M_List1[(int)e_RegionCheck.切图区域],
        //                //                (int)nud_m_grayMin.Value, (int)nud_m_grayMax.Value, out HObject threadObj);
        //                GlobalVar.imageDisplay3_obj(threadObj, "red");
        //                HOperatorSet.GetRegionPoints(threadObj, out HTuple rs, out HTuple cs);
        //                bool IsHave = rs.Length > (int)nud_m_AreaMin.Value && rs.Length < (int)nud_m_AreaMax.Value;
        //                textBox2.Text = rs.Length.ToString("F03");
        //                displalyInfo.displayInfoMain($"有效面积为{rs.Length} *****为无文字板*****");
        //            }
        //        }
        //        else
        //        {
        //            if (IndexSelect > 1)
        //            {
        //                GlobalVar.imageDisplay3_obj(visionProc.ROI_M_List2[IndexSelect], "green");
        //                var res = visionProc.GetMeasures(e_CameraPlate.检测相机平台2, Get_Measure(), e_Region);
        //                var n = res == null ? 0 : res.Count;
        //                displalyInfo.displayInfoMain($"该区域有{n}匹配对" + (n > 0 ? string.Join(",", res) : 0.ToString()));
        //            }
        //            else
        //            {
        //                HOperatorSet.ReduceDomain(visionProc.srcObject_ckeck, visionProc.ROI_M_List2[(int)e_RegionCheck.切图区域], out HObject cutObj);
        //                HOperatorSet.Threshold(cutObj, out HObject threadObj, (int)nud_m_grayMin.Value, (int)nud_m_grayMax.Value);
        //                //visionProc.GetCutResult(visionProc.srcObject_ckeck, visionProc.ROI_M_List1[(int)e_RegionCheck.切图区域],
        //                //              (int)nud_m_grayMin.Value, (int)nud_m_grayMax.Value, out HObject threadObj);
        //                GlobalVar.imageDisplay3_obj(threadObj, "red");
        //                HOperatorSet.GetRegionPoints(threadObj, out HTuple rs, out HTuple cs);
        //                bool IsHave = rs.Length > (int)nud_m_AreaMin.Value && rs.Length < (int)nud_m_AreaMax.Value;
        //                textBox2.Text = rs.Length.ToString("F03");
        //                displalyInfo.displayInfoMain($"有效面积为{rs.Length} *****为无文字板*****");
        //            }
        //        }
        //    }
        //}

        OpenFileDialog open_file1 = new OpenFileDialog();
        private void btn_status_Click(object sender, EventArgs e)
        {
            open_file1.FilterIndex = 1;
            open_file1.RestoreDirectory = true;
            open_file1.Filter = "sol文件(*.sol)|*.sol";
            open_file1.InitialDirectory = Application.StartupPath + "\\Engineering";
            if (open_file1.ShowDialog() == DialogResult.OK)
            {
                if (open_file1.FileName.Trim() == "") return;
                string filepath = open_file1.FileName;
                textBox3.Text = filepath;
            }
        }


    }
}
